【发布时间】:2018-08-26 21:40:44
【问题描述】:
我创建了一个 .htaccess 文件。 madewithlove 的 htaccess 测试器 (https://htaccess.mwl.be) 的测试表明 URL 重写是正确的,但实时测试返回 404 错误。
我要重写的网址:
http://example.com/folder1/folder2/word123 // 重定向到
https://example2.com/en/?key=word123
我的 .htaccess:
# BEGIN WordPress
<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
# BEGIN Part that is not working
Options -Multiviews
RewriteEngine On
RewriteBase /
RewriteRule ^folder1/folder2/(.*)$ https://example2.com/en/?key=$1 [R=301,L,NE]
# End part that is not working
我正在使用带有 Apache 2.4.3-25 的 GoDaddy 共享主机。 WordPress 行工作。如果它们被删除,那么 Wordpress 页面和博客链接会中断。
我认识到这个问题类似于 URL Rewrite keeps returning 404 Error,但 martoio 是从现有文件重定向的。
我尝试了 Friendly URLS / URL Rewriting using .htaccess on godaddy shared server 上提供的 Siraj Khan 和 Gautam Jha 的解决方案,但均无济于事。
我不知道该怎么做,非常感谢您的帮助。
这是包含neokio建议后的修改版:
# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php
</IfModule>
# END WordPress
# BEGIN Part that is not working
Options -Multiviews
RewriteEngine On
RewriteBase /
RewriteRule ^folder1/folder2/(.*)$ https://example2.com/en/?key=$1 [R=301,L,NE]
# End part that is not working
【问题讨论】:
-
我相信第 5 行 ...
RewriteRule ^index\.php$ - [L]... 是多余的,或者至少会干扰后面的内容。尝试删除它,也许有帮助? -
感谢您的回复。我删除了第五行,它的工作原理相同。我将省略该行,因为它似乎是多余的。之后我还删除了 [L] 参数,因为 madewithlove 似乎说它在那时停止了处理。但仍然返回 404 错误。
-
感谢您的想法,其他东西可能会干扰第一个,neokio。我开始浏览我的文件,并在文件夹 1 中找到了一个 .htaccess。我删除了那个 .htaccess 并且第一个工作正常。
标签: wordpress apache .htaccess mod-rewrite url-rewriting