简体   繁体   English

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

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

I have some simple RewriteRules that redirect all path variables to /index.php. 我有一些简单的RewriteRules,可以将所有路径变量重定向到/index.php。 But now I'm looking to make an exception for all /img/(.*) urls. 但是现在我希望为所有/img/(.*)网址设置一个例外。

Here's a snippet. 这是一个片段。 Please advise. 请指教。

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]

I tried adding RewriteRule ^img/(.*) img/index.php/$1 [L] just above the last catchall line but it's not working. 我试着在最后一个包罗万象的行上方添加RewriteRule ^img/(.*) img/index.php/$1 [L] ,但它不起作用。

The result I'm after is something like this: 我追求的结果是这样的:

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

Can you point me in the right direction? 你能为我指出正确的方向吗?

You need to add it not just above the last catchall line, but leave the conditions required by the catchall and likewise duplicate them for your own /img/ routing: 您不仅需要将其添加到最后一个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