包含文件扩展名时 RewriteRule 不起作用
嘿,我正在尝试使用 mod_rewrite 使 http://example.com/style/universal.css
显示页面 http://example.com/style.php?n=通用
我目前正在使用以下RewriteRule
:
RewriteRule ^style/([^/\.]+)\.css$ style.php?n=$1
但它似乎不起作用,由于某种原因它反而显示404 Not Found
,这甚至不是正确的404页面。
我尝试过在没有扩展名 .css
(即 http://example.com/style/universal
)的情况下使用 RewriteRule
进行此
RewriteRule ^style/([^/\.]+)$ style.php?n=$1
操作,效果很好,但如果我能让它与 .css
扩展一起使用,我会更喜欢它。
如果使用文件扩展名,服务器似乎会忽略 RewriteRule。是否有 RewriteCond
或者我遗漏的明显内容?
我还应该提到的是,在 WordPress 设置的父目录中有一个.htaccess
,其内容是:
RewriteEngine on
# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>
# END WordPress
任何帮助将不胜感激。
预先感谢,布拉德。
Hey, I am trying to use mod_rewrite to make http://example.com/style/universal.css
show the page http://example.com/style.php?n=universal
I am currently using the following RewriteRule
:
RewriteRule ^style/([^/\.]+)\.css$ style.php?n=$1
But it doesn't seem to work, for some reason it instead shows a 404 Not Found
which is not even the correct 404 page.
I have tried doing it without the extension .css
(i.e. http://example.com/style/universal
) with the RewriteRule
RewriteRule ^style/([^/\.]+)$ style.php?n=$1
Which works, but I would much prefer it if I could get it working with the .css
extension.
It seems to be something with the server ignoring the RewriteRule if a file extension is used. Is there a RewriteCond
or something obvious that I am missing?
I should also mention that there is a .htaccess
in the parent directory which is set by WordPress, the contents of this are:
RewriteEngine on
# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>
# END WordPress
Any help would really be appreciated.
Thanks in advance, Brad.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
设置你的 mod_rewrite 来记录它处理你的 url 的所有步骤
,阅读日志你应该能够了解你的 url 是如何重写的以及问题是什么。
Set up your mod_rewrite to log all the steps it does processing your url
reading the logs you should be able to understand how your url is rewritten and what is the problem.