SEO friendly URLS HTACCESS PHP
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.phpThis 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.
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).
精彩评论