包含文件扩展名时 RewriteRule 不起作用

发布于 2024-10-07 12:55:55 字数 1040 浏览 0 评论 0原文

嘿,我正在尝试使用 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

温柔女人霸气范 2024-10-14 12:55:55

设置你的 mod_rewrite 来记录它处理你的 url 的所有步骤

RewriteLog "/tmp/mysite_rewrite.log"
RewriteLogLevel 6

,阅读日志你应该能够了解你的 url 是如何重写的以及问题是什么。

Set up your mod_rewrite to log all the steps it does processing your url

RewriteLog "/tmp/mysite_rewrite.log"
RewriteLogLevel 6

reading the logs you should be able to understand how your url is rewritten and what is the problem.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文