除了 Wordpress 之外还重写规则'
因此,除了 WordPress 已有的规则之外,我还尝试添加自己的 RewriteRule。一点背景。我正在开发的网站是基于自定义 CMS 构建的,但也有一个由 WordPress 提供支持的博客。所以,这就是我到目前为止所得到的:
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
# Custom rewrite for locatons
RewriteRule ^locations/(.*)$ /locations2.php?info=$1
# Wordpress rewrite
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /blog/index.php [L]
</IfModule>
我还删除了几行似乎不必要的 WordPress Rewrite 代码(一切仍然有效......我认为)。但是,是的,它似乎覆盖了我写的规则。帮助?
哦,另外,我只是试图去掉 /blog/index.php [L] 之前的 .
并将其替换为 ^
,它起作用了。 ..有点儿。当我访问 /blog/ 时,它加载了博客,但是当我访问 /blog/author/admin 之类的内容时,我得到了 404。
So, I'm trying to add my own RewriteRule in addition to what Wordpress already has. A little backgroun. The site I am working on is built off of a custom CMS, but also has a blog that is powered by WordPress. So, heres what I have thus far:
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
# Custom rewrite for locatons
RewriteRule ^locations/(.*)$ /locations2.php?info=$1
# Wordpress rewrite
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /blog/index.php [L]
</IfModule>
I also got rid of a couple lines of the Wordpress Rewrite code that seemed unecessary (everything still works....I think). But yeah, it seems like it is overwriting the rule that I wrote. Help?
Oh, also, I just tried to get rid of the .
that is before /blog/index.php [L] and replaced it with just a ^
, it worked...kind of. It loaded the blog when I went to /blog/, but when I went to something like /blog/author/admin, I got a 404.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我认为您需要在新规则后添加最后一个标志
[L]
,否则处理将继续,您的请求将被重写为“/blog/index.php”。I think you need to add the last flag
[L]
after your new rule, otherwise processing will continue and your request will be rewritten to '/blog/index.php'.您是否尝试删除 Locations2.php 之前的
RewriteBase /
和斜杠?像这样的事情:
如果博客无法访问,请将
RewriteBase /
移至自定义重写之后。另外,我相信如果博客位于子目录中,则 RewriteBase 应该是RewriteBase /blog/
Have you tried to remove the
RewriteBase /
and the slash before locations2.php ?Something like this:
If the blog gets unreacheable, move
RewriteBase /
to after the custom rewrite. Also, I believe that if the blog is in a sub-directory, the RewriteBase should beRewriteBase /blog/