的.htaccess URL重写不工作
我写.htaccess文件转换网址,搜索引擎友好:的.htaccess URL重写不工作
原始URL是:
http://palestinianz.com/?page=person&p=Alex-Atalla
的.htaccess的内容是:
RewriteEngine On
RewriteRule ^([^/]*)\.html$ /?page=person&p=$1 [L]
它应该产生这样的链接:
http://palestinianz.com/Alex-Atalla.html
但是,尽管我把文件放在我的网站的根目录下,但它没有任何效果! 问题在哪里?
如果你想要的网址在地址栏中改变,你需要重定向浏览器,然后在服务器上重写。这个答案的第一部分介绍了所需的过程:https://stackoverflow.com/a/11711948/851273
所以在看第二个列表,这个过程是将浏览器重定向如果一个丑陋的链接请求一个很好看的链接:
RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /\?page=person&p=([^\ ]+)
RewriteRule ^$ /%1.html? [R=301,L]
现在,在服务器端,你需要internall改写回丑陋的网址,这是多了还是少了什么,你已经有了:
RewriteRule ^([^/]*)\.html$ /?page=person&p=$1 [L]
你可以试试:
RewriteCond %{REQUEST_URI} (.+)\.html$
RewriteRule ^(.+)\.html$ ./index.php?page=person&p=$1 [L]
只有这个问题是任何.html
页面将通过这一点。可能要更改为以下内容:
# URL: domain.com/person/Alex-Atalla.html
RewriteCond %{REQUEST_URI} (.+)/(.+)\.html$
RewriteRule ^(.+)/(.+)\.html$ ./index.php?page=$1&p=$2 [L]
这将让你有更多的鲁棒性改变页面变量以及
这个代码 RewriteEngine叙述在 重写规则^([^ /] *) \ .html $ /?page = person&p = $ 1 [L] wo除了它不会改变地址栏中的网址,我的意思是:加入.htaccess后: http://palestinianz.com/Alex-Atalla.html和 http://palestinianz.com/?page=人&p = Alex-Atalla正在工作 但问题是url仍然是:http://palestinianz.com/?page=person&p=Alex-Atalla在地址栏中! – 2012-07-31 16:23:30
谢谢你正在工作!但你能解释规则吗? – 2012-07-31 18:56:41