Reputation: 23
I'm trying to rewrite my portfolio URLs within a htaccess
file. I have this code and it work to some extent.
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_URI} !(\.[a-zA-Z0-9]{1,5}|/|#(.*))$
RewriteRule ^(.*)$ $1/ [R=301,L]
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}\.php -f
RewriteRule ^([^\.]+)/$ $1.php
However the issue is that I have a blog in a folder and when I try to go to another page from the blog page the URL does not get formatted right.
Ex. cgarcia.design/blog/about/
and it should be cgarcia.design/about/
.
Any suggestions on how I can fix the code to properly rewrite my URLs with a trailing slash that also work with sub directories?
Upvotes: 0
Views: 40
Reputation: 2807
use the below line of code:
RewriteRule blog/(.*) / [L]
Which basically means that whatever the request that comes as blog/any_name_here should be rewritten as /
Upvotes: 1