htaccess 正则表达式通配符重定向覆盖其他重定向
我目前在 htaccess 中有以下重定向,我需要添加两个新的重定向。尽管看起来最后一个通配符重定向覆盖了我试图添加的两个新重定向。我该如何纠正这个问题?有什么建议吗?谢谢。
RewriteEngine On
RewriteCond %{HTTP_HOST} ^mydomain.com
RewriteRule (.*) http://www.mydomain.com/$1 [R=301,L]
RewriteRule ^.*.(jpe?g|gif|png|bmp|ico|swf|gz|xml|htm?l|pem|txt)$ - [L]
RewriteCond %{ SCRIPT_FILENAME} !^apanel/*
RewriteRule ^(.*) process.php [L]
我尝试添加的新重定向如下:
RewriteRule ^cs/(.*.css) /shared.php?type=css& ;files=$1
RewriteRule ^jscript/(.*.js) /shared.php?type=js&files=$1
I currently have the following redirects in htaccess, and I need to add two new redirects. Though it appears the last wildcard redirect is overriding the two new redirects which I am trying to add. How do I correct this? Any suggestions? Thank you.
RewriteEngine On
RewriteCond %{HTTP_HOST} ^mydomain.com
RewriteRule (.*) http://www.mydomain.com/$1 [R=301,L]
RewriteRule ^.*.(jpe?g|gif|png|bmp|ico|swf|gz|xml|htm?l|pem|txt)$ - [L]
RewriteCond %{SCRIPT_FILENAME} !^apanel/*
RewriteRule ^(.*) process.php [L]
And the new redirects I am trying to add are as follows:
RewriteRule ^cs/(.*.css) /shared.php?type=css&files=$1
RewriteRule ^jscript/(.*.js) /shared.php?type=js&files=$1
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
好吧,正如我读到的,您最后的 RewriteCond/RewriteRule 说“如果文件名不在“apanel”文件夹中,则将其重定向到 process.php 并停止”。您的两个新规则将首先匹配该规则,并且 mod_rewrite 将停止处理进一步的指令。
如果您将两个新规则放在最后一个条件/规则组合之上并使用 [L] 标志,它们应该可以正常工作......
Well as I read it your last RewriteCond/RewriteRule says "if the filename isn't in the 'apanel' folder redirect it to process.php and stop". Both of your new rules would match that rule first and mod_rewrite would stop processing further directives.
If you put your two new rules above your last Cond/Rule combo and use the [L] flag they should work properly....