【发布时间】:2020-08-05 16:38:08
【问题描述】:
我正在尝试重定向以下内容...
-
http://example.com/blog/article-name到 http://example.com/blog/news/article-name
.. 这很好用..
RewriteCond %{REQUEST_URI} !^/blog/news
RewriteRule ^blog/(.*) /blog/news/$1 [QSA,L,R=301]
它停止了无限重定向循环......
但是,我不想要这个 URL..
http://example.com/blog/
重定向到任何地方,因为这是我列出所有博客条目的登录页面...目前我在这里遇到无限循环。
http://example.com/blog/news/news/news/news/news/news/news/news/news/news/news/news/news/news/news/news/news/news/
我已经尝试添加另一个条件来阻止根页面被重定向...
RewriteCond %{REQUEST_URI} !^/blog/$
但这不起作用...
仅供参考
这是我完整的.htaccess 文件
# BEGIN WordPress
# The directives (lines) between `BEGIN WordPress` and `END WordPress` are
# dynamically generated, and should only be modified via WordPress filters.
# Any changes to the directives between these markers will be overwritten.
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>
# END WordPress
RewriteCond %{REQUEST_URI} !^/blog/news
RewriteRule ^blog/(.+) /blog/news/$1 [L,R=301]
有什么想法吗?
【问题讨论】:
-
这些指令本身不会导致“重定向循环”。这更有可能是由于与其他指令的冲突。请编辑您的问题以包含您的
.htaccess文件的全部内容以及您在文件系统路径中可能拥有的任何其他.htaccess。 -
没有问题...应该说它是一个简单的 WP 网站...
-
/blog和/blog/news是否作为物理目录存在,或者它们是 WordPress 虚拟 URL 的一部分?
标签: .htaccess redirect mod-rewrite