1

How can I change my URL from showing: www.example.com/p/tools to just www.example.com/tools?

I've tried to play around with the .htaccess a little bit, but unfortunately couldn't make it work.

<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{SERVER_PORT} 80
RewriteRule ^(.*)$ https://www.example.com/$1 [R,L]

RewriteCond %{REQUEST_FILENAME}.html -f
RewriteRule ^ %{REQUEST_URI}.html [NC,L]
</IfModule>
2
  • 1
    Welcome to SO, kindly do share your htaccess Rule file in your question thank you Commented Mar 3, 2021 at 22:10
  • 1
    @RavinderSingh13 Thank you for your kindness. I just uploaded that right away! :-) Commented Mar 4, 2021 at 3:23

1 Answer 1

1

Based on your shown samples, could you please try following.

Please make sure to clear your browser cache before testing your URLs

<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{SERVER_PORT} 80
RewriteRule ^(.*)$ https://www.example.com/$1 [R,L]

RewriteRule ^p/(.*)/?$ $1 [NC,R=301,L]

RewriteCond %{THE_REQUEST} /([^.]+)\.html [NC]
RewriteRule ^ /%1 [NC,L,R]

RewriteCond %{REQUEST_FILENAME}.html -f
RewriteRule ^ %{REQUEST_URI}.html [NC,L]
</IfModule>
Sign up to request clarification or add additional context in comments.

11 Comments

Hmm, i mean. The /p is gone now, but i have another problem. The URL now turns to: https://www.example.com/public_html/tools and gives me a "404 Not Found" error :/
@Berkanktk, I honestly thought about it, so for non existing files and directories to which file(index.php OR index.html) you want it to rewrite? If you can let me know this one I can fix it, cheers.
I'm sorry, but i am not sure i understand what you mean by that. I have a html.index though. If that helps?
@Berkanktk, you are getting 404 because that page/directory doesn't exist, that's why I asked if a page is non existing then to which file it should point out in backend?
Yea sorry it's 3 AM i Denmark right now, so soon it will be my turn :p. Okay so here it is, all of them: Root directory, p and images
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.