Mod rewrite 使用_请求重写apachemod
我想用apache(mod rewrite)执行以下操作Mod rewrite 使用_请求重写apachemod,mod-rewrite,Mod Rewrite,我想用apache(mod rewrite)执行以下操作 如果用户请求,我希望它重定向(R=301)到 如果用户请求,则应在内部将请求重写为index.php/folder/subfolder 为了防止无止境的重定向,第一条规则应该检查%{the_REQUEST}。这里的问题是我无法用正则表达式附加“文件夹/子文件夹”。我该怎么做 对于第二条规则,我有这个(而且似乎有效) 第一个仍然是个问题 我想第一个应该是 RewriteCond %{THE_REQUEST} (.*)index.php(.*
RewriteCond %{THE_REQUEST} (.*)index.php(.*) [NC]
RewriteRule /index.php/$ http://hostname.tld/$1 [R=301,QSA,L]
但事实并非如此。第一个应该是
RewriteCond %{HTTP_HOST} ^hostname\.tld$ [NC]
RewriteCond %{THE_REQUEST} index\.php [NC]
RewriteRule ^index.php/(.*)$ http://hostname.tld/$1 [R=301,L]
我还看到您的第二条规则重定向http://hostname.tld/folder/subfolder
至http://hostname.tld/index.php
(非http://hostname.tld/index.php/folder/subfolder
)。但是,只要这样做有效,就可以了,因为这样也可以防止重定向循环。
但为了以防万一,以下是添加文件夹/子文件夹部分的解决方案:
RewriteCond %{HTTP_HOST} ^hostname\.tld$ [NC]
RewriteCond $1 !^index\.php
RewriteRule ^(.*)$ index.php/$1 [QSA,L]
RewriteCond %{HTTP_HOST} ^hostname\.tld$ [NC]
RewriteCond $1 !^index\.php
RewriteRule ^(.*)$ index.php/$1 [QSA,L]