两次htacces重写

时间:2017-03-29 00:21:19

标签: .htaccess mod-rewrite

我需要做这样的事情:
1重写:

  

强制:localhost / main / ==>本地主机

2重写:

  

localhost /?api = test123& page = m1 ==>本地主机/ test123 / M1

如果api为空,请转到第

  

localhost / m1 =>页面:m1(在此网址中,用户不要求api)

我有这个htaccess:

RewriteCond %{REQUEST_URI} !main/
RewriteRule (.*) /main/$1 [L]
RewriteRule ([^/]*)/([^/]*)/$ /main/index.php?api=$2&page=$3 [L]

感谢和抱歉我的英语不好。

1 个答案:

答案 0 :(得分:0)

这是awnser:

RewriteRule ^page/([^/]*)/$ /main/index.php?page=$1 [QSA,L] [OR]
RewriteRule ^api/([^/]*)/$ /main/index.php?api=$1 [QSA,L] [OR]

RewriteCond %{REQUEST_URI} !main/
RewriteRule (.*) /main/$1