我正准备开发一个具有以下url结构的网站.
我是urre重写的新手,想知道解决这个问题的最佳方法.
http://domain.com index.php
http://domain.com/about about.php
http://domain.com/agencies agencies.php
http://domain.com/contact contact.php
http://domain.com/publisher publisher.php
http://domain.com/publisher/sign_up publisher_signup.php
http://domain.com/agencies/sign_up agencies_signup.php
http://domain.com/agencies/login login.php
http://domain.com/advertiser advertiser.php
http://domain.com/advertiser/sign_up advertiser_signup.php
http://domain.com/advertiser/login login.php
什么是最有效的htaccess重写?
我应该只是通过重写手动输入每一行,还是我可以使用一些好的搜索/替换?
我想长期来看,网址中的斜线数量最多可能是4
例如
http://domain.com/area/sub_area/sub_area2/sub_area3
任何帮助将不胜感激.
最佳答案 我很抱歉,但你的“URL”转换并不是同质的(=它不可能“概括”因为它们没有完全相同的原则)所以这是我能做的最好的:
RewriteEngine On
^/?$index.php [NC,QSA,L]
^/?about$about.php [NC,QSA,L]
^/?(agencies|contact|publisher|advertiser)$/$1.php [NC,QSA,L]
^/?(publisher|agencies|advertiser)/sign_up$ /$1_signup.php [NC,QSA,L]
^/?(publisher|agencies|advertiser)/login$ /login.php [NC,QSA,L]
但是如果你想要“同质”的东西并不完全符合你所要求的东西,你可能会有这样的“更清洁”的规则:
RewriteEngine On
^/?$index.php [NC,QSA,L]
^/?about$about.php [NC,QSA,L]
^/?(agencies|contact|publisher|advertiser)$/$1.php [NC,QSA,L]
^/?(agencies|contact|publisher|advertiser)/sign_up$/$1_signup.php [NC,QSA,L]
^/?(agencies|contact|publisher|advertiser)/login$/login.php [NC,QSA,L]
如果你真的想集中所有东西,你可以做(=将类型传递给php文件):
RewriteEngine On
^/?$index.php [NC,QSA,L]
^/?about$about.php [NC,QSA,L]
^/?(agencies|contact|publisher|advertiser)$/$1.php [NC,QSA,L]
^/?(agencies|contact|publisher|advertiser)/(sign_up|login)$/$2.php?type=$1 [NC,QSA,L]