搜索引擎友好的URLS .htaccess的PHP [英] 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.php
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/
http://www.website.com/page1/
http://www.website.com/page2/
http://www.website.com/page3/
什么是做到这一点不把每个文件在自己的目录和index.php文件命名它们的最好方法。
What is the best way to do this without putting each of the files in their own directory and naming them index.php.
思路吧。
推荐答案
使用Apache 的mod_rewrite
。将这个在的.htaccess
:
Use apache mod_rewrite
. Put this in the .htaccess
:
RewriteEngine on
RewriteCond %{SCRIPT_FILENAME} !-f
RewriteCond %{SCRIPT_FILENAME} !-d
RewriteRule ^([^/]+)/?$ $1.php [L]
这将捕获的表格的所有请求的路径 / SomePage的
或 / SomePage的/
,并将其重定向到<$ C C> /somepage.php (除非请求路径是指服务器上的实际文件或目录 - 在这种情况下,它只会成为该文件或目录)。
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).
这篇关于搜索引擎友好的URLS .htaccess的PHP的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!