开发者

SEO friendly URLS HTACCESS PHP

开发者 https://www.devze.com 2023-01-25 05:50 出处:网络
On my website I have created my pages like so: http://www.website.com/page1.php http://www.website.com/page2.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.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.


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).

0

精彩评论

暂无评论...
验证码 换一张
取 消