Reputation: 1045
I'm trying to make a .htaccess page that can change my url from www.site.com/about.php to /About/. All the pages are in the root currently so I'll want to do this for multiple pages. So far I have this in my htaccess file:
RewriteEngine On
RewriteCond %{SCRIPT_FILENAME} !-d
RewriteCond %{SCRIPT_FILENAME} !-f
RewriteCond %{SCRIPT_FILENAME} !-l
RewriteRule ^(.*)$ about.php [QSA,L]
This seems to just change all pages other than the index.php to the about page. My hyperlinks in the nav now go to /About/, /Contact/ etc but I can't work out what I need to change to make the links that aren't about stop showing the about.php.
Any help would be great with this as I'm very new to PHP. Thanks in advance for any guidance
Upvotes: 0
Views: 81
Reputation: 728
You are matching ALL requests with
^(.*)$
and sending them to 'about.php'.
What you want to do is match the request, then use that match to construct the file name:
# Get the Request
RewriteCond %{REQUEST_FILENAME} ^(.*)$
# Check that the file exists, using the match from above (%1)
RewriteCond %1\.php -f
RewriteRule ^(.*)$ $1.php [QSA,L]
This is a very basic way to do it. You probably want to enhance the rule so it only match on the first URL part.
Upvotes: 1