除了 Wordpress 之外还重写规则'

发布于 2024-11-07 09:32:56 字数 682 浏览 0 评论 0原文

因此,除了 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 技术交流群。

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

发布评论

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

评论(2

调妓 2024-11-14 09:32:56

我认为您需要在新规则后添加最后一个标志 [L],否则处理将继续,您的请求将被重写为“/blog/index.php”。

RewriteRule ^locations/(.*)$  /locations2.php?info=$1 [L]

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'.

RewriteRule ^locations/(.*)$  /locations2.php?info=$1 [L]
ぃ双果 2024-11-14 09:32:56

您是否尝试删除 Locations2.php 之前的 RewriteBase / 和斜杠?

像这样的事情:

<IfModule mod_rewrite.c>
    RewriteEngine On

    # 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>

如果博客无法访问,请将 RewriteBase / 移至自定义重写之后。另外,我相信如果博客位于子目录中,则 RewriteBase 应该是 RewriteBase /blog/

Have you tried to remove the RewriteBase / and the slash before locations2.php ?

Something like this:

<IfModule mod_rewrite.c>
    RewriteEngine On

    # 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>

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 be RewriteBase /blog/

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