动态 301 重定向与 WordPress 的战斗

发布于 2024-11-02 08:37:53 字数 1140 浏览 1 评论 0原文

这是我之前提出的另一个问题的后续问题(之前的重定向问题)。我的根 .htaccess 有几个这种格式的规则:

RewriteCond %{REQUEST_URI} ^/leadership/detail/$
RewriteCond %{QUERY_STRING} q=([0-9]+)$ 
RewriteRule ^(.*)$ /$1?p=%1 [L,R=301]

但是当我尝试添加此内容时:

RewriteCond %{REQUEST_URI} ^/blog/detail/$
RewriteCond %{QUERY_STRING} q=([0-9]+)$ 
RewriteRule ^(.*)$ /$1?p=%1 [L,R=301]

它不起作用。 /blog/ 是一个 Wordpress 安装,我认为它与 /blog/ 中的 .htaccess 文件冲突,该文件具有以下内容:

<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /blog/
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /blog/index.php [L]
</IfModule>

# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /blog/
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /blog/index.php [L]
</IfModule>

# END WordPress

Where can I insert (or edit) code snippet #2 in the /blog/.htaccess file使其正常工作?

This is a followup to another question I asked earlier (Earlier redirect question). My root .htaccess has several rules in this format:

RewriteCond %{REQUEST_URI} ^/leadership/detail/$
RewriteCond %{QUERY_STRING} q=([0-9]+)$ 
RewriteRule ^(.*)$ /$1?p=%1 [L,R=301]

But when I tried to add this:

RewriteCond %{REQUEST_URI} ^/blog/detail/$
RewriteCond %{QUERY_STRING} q=([0-9]+)$ 
RewriteRule ^(.*)$ /$1?p=%1 [L,R=301]

It didn't work. /blog/ is a Wordpress install and I'm thinking in it's conflicting with the .htaccess file that's in /blog/ that has the following:

<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /blog/
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /blog/index.php [L]
</IfModule>

# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /blog/
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /blog/index.php [L]
</IfModule>

# END WordPress

Where can I insert (or edit) code snippet #2 in the /blog/.htaccess file to make it work properly?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

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

发布评论

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

评论(1

初见 2024-11-09 08:37:53

让您的组合 .htaccess 如下所示:

# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On

RewriteCond %{REQUEST_URI} ^/blog/detail/$
RewriteCond %{QUERY_STRING} q=([0-9]+)$ [NC]
RewriteRule ^(.*)$ /blog/$1?p=%1 [L,R=301]

RewriteBase /blog/
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{QUERY_STRING} !^p= [NC]
RewriteRule . /blog/index.php [L]
</IfModule>

# END WordPress

Have your combined .htaccess like this:

# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On

RewriteCond %{REQUEST_URI} ^/blog/detail/$
RewriteCond %{QUERY_STRING} q=([0-9]+)$ [NC]
RewriteRule ^(.*)$ /blog/$1?p=%1 [L,R=301]

RewriteBase /blog/
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{QUERY_STRING} !^p= [NC]
RewriteRule . /blog/index.php [L]
</IfModule>

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