Reputation: 7827
On my website I have created my pages like so:
http://www.website.com/page1.php
http://www.website.com/page2.php
http://www.website.com/page3.php
This is not SEO friendly, I really want to display them like this:
http://www.website.com/page1/
http://www.website.com/page2/
http://www.website.com/page3/
What is the best way to do this without putting each of the files in their own directory and naming them index.php.
Ideas please.
Upvotes: 1
Views: 1544
Reputation: 53309
Use apache mod_rewrite
. Put this in the .htaccess
:
RewriteEngine on
RewriteCond %{SCRIPT_FILENAME} !-f
RewriteCond %{SCRIPT_FILENAME} !-d
RewriteRule ^([^/]+)/?$ $1.php [L]
This will catch all request paths of the form /somepage
or /somepage/
and redirect them to /somepage.php
(unless the request path refers to an actual file or directory on the server -- in which case it will just serve that file or directory).
Upvotes: 5