繁体   English   中英

如何将所有以img /开头的URL请求重定向到index.php / path / variables?

[英]How can I redirect all url requests to index.php/path/variables except those starting with img/?

我有一些简单的RewriteRules,可以将所有路径变量重定向到/index.php。 但是现在我希望为所有/img/(.*)网址设置一个例外。

这是一个片段。 请指教。

RewriteEngine On
RewriteCond %{HTTP_HOST} ^www\.(.*)$ [NC]
RewriteRule ^(.*)$ http://%1/$1 [R=301,L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule (.*) index.php/$1 [L]

我试着在最后一个包罗万象的行上方添加RewriteRule ^img/(.*) img/index.php/$1 [L] ,但它不起作用。

我追求的结果是这样的:

url      --> script / path variables
====================================
/abc/def --> /index.php/abc/def
/img/abc --> /img/index.php/abc

你能为我指出正确的方向吗?

您不仅需要将其添加到最后一个catchall行的上方,还需要保留catchall所需的条件,并同样为您自己的/img/路由复制它们:

RewriteEngine On

RewriteCond %{HTTP_HOST} ^www\.(.*)$ [NC]
RewriteRule ^(.*)$ http://%1/$1 [R=301,L]

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^img/(.*) img/index.php/$1 [L]

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule (.*) index.php/$1 [L]

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM