0

如何翻译如下 URL: http://localhost/mySite/?link=OFFERS&sublink=ARTICLE&subsublink=DETAIL

至: http://localhost/mySite/OFFERS/ARTICLE/DETAIL

如果一个参数为空,它仍然应该像这样工作:localhost/mySite/?link=OFFERS&sublink=ARTICLE localhost/mySite/OFFERS/ARTICLE

额外问题:index.php 下有一个进入页面,重写应该与 index2.php 一起工作。最好是它可以在 localhost 和实时系统上运行而无需更改。

目前我正在使用: RewriteRule ^([^/.]+)$ index2.php?link=$1 [L] 但这仅适用于一个参数,我无法改进这段代码多年^^

4

2 回答 2

0

尝试将以下内容添加到mysite站点目录中的 htaccess 文件中。

RewriteEngine on
RewriteBase /mysite/

# rewrite http://localhost/mySite/OFFERS/ARTICLE/DETAIL to
# http://localhost/mySite/?link=OFFERS&sublink=ARTICLE&subsublink=DETAIL
#assumes that index2.php is in the root directory of site
RewriteRule ^([-a-zA-Z0-9])+/([-a-zA-Z0-9])+/([-a-zA-Z0-9])+ index2.php?link=$1&sublink=$2&subsublink=$3 [NC,L]

#redirect index to index2
#if you do not want to redirect, just server rewrite, remove the R=301 below
RewriteRule ^index\.php$ index2.php [NC,L,R=301]
于 2012-01-22T13:52:16.230 回答
0
RewriteRule ^([^/.]+)(/([^/.]+))?(/([^/.]+))?$ index2.php?link=$1&sublink=$3&subsublink=$5 [L,QSA]

请注意,localhost/mySite/OFFERS/ARTICLE链接到localhost/mySite/?link=OFFERS&sublink=ARTICLE&sussublink=而不是localhost/mySite/?link=OFFERS&sublink=ARTICLE. 应该不是什么大问题,但要确保 PHP 代码不是我们的isset($_GET['subsublink']).

于 2012-01-22T15:22:11.410 回答