问题描述
我正准备开发具有以下url结构的网站。
I'm getting ready to develop a web site with the following url structure.
我是URL重写的新手,并且想知道最好的方法
I'm a newbie to url rewrites and would like to know the best way to handle this.
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重写器是什么?
What would be the most efficient htaccess rewriterule?
我应该手动输入每行进行重写还是有一些好处我可以使用搜索/替换吗?
Should I just manually enter each line with a rewrite or is there some good search/replace I could use?
例如,我长期认为网址中的斜杠数量最多为
I'm thinking long term the number of slashes in the url could be the most 4for example
http://domain.com/area/sub_area/sub_area2/sub_area3
任何帮助将不胜感激。
推荐答案
对不起但是您的 URL转换不是同质的(=无法通用化,因为它们没有完全相同的原理),所以这是我能做的最好的事情:
I'm sorry but your "URL" transformation are not homogeneous (= it's not possible to "generalize" because they do not share exactly the same principles) so here's the best I could do:
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]
但是,如果您想要的均质东西与您的要求不完全相符,您可能会精简规则,例如:
But if you want "homogeneous" stuff that do not perfectly fit with what you're asking, you may have "cleaner" rules like this:
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
文件):
And if you really want to centralize everything, you could do (= pass the type to the php
file):
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]
这篇关于URL重写.htaccess的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!