我正在将客户端从自定义开发的PHP站点移动到Wordpress。我现在正在使用.htaccess文件中的301重定向来将旧位置移动到Wordpress中的新位置。其中一些正在工作而一些不工作(意味着它提供“旧”位置)。我在文件中有标准的“漂亮的永久链接”mod_rewrite部分,然后是所有的301。
因此,那些具有原始位置的列表就像目录(重写的index.php)一样工作,那些具有明确命名的php文件的那些不起作用。例子:
这有效:
Redirect 301 /about/ http://deanchiropractic.com/about-us/
这样做(仍然服务于dr-jon.php):
Redirect 301 /about/dr-jon.php http://deanchiropractic.com/about-us/dr-jon-dean/
我试过更改顺序,尝试在mod-rewrite部分之前和之后使用301s,尝试使用和不使用DirectoryIndex行。我还验证了我正在编辑网络服务器根目录中的.htaccess。
我宁愿让我的.htaccess工作,而不是让php在所有未重定向的文件中执行301重定向(我已经尝试过,并使用一个文件进行了验证)。
以下是整个参考资料:
DirectoryIndex index.php index.html
Redirect 301 /about/dr-dean.php http://deanchiropractic.com/about-us/christophe-dean-dc/
Redirect 301 /about/dr-jon.php http://deanchiropractic.com/about-us/dr-jon-dean/
Redirect 301 /techniques/activator.php http://deanchiropractic.com/chiropractic-techniques/activator-method/
Redirect 301 /techniques/cox-technique.php http://deanchiropractic.com/chiropractic-techniques/cox-technique/
Redirect 301 /techniques/active-release.php http://deanchiropractic.com/chiropractic-techniques/active-release-technique/
Redirect 301 /community/dinner-talk.php http://deanchiropractic.com/get-healthy/
Redirect 301 /community/refer.php http://deanchiropractic.com/get-healthy/
Redirect 301 /resources/forms.php http://deanchiropractic.com/forms/
Redirect 301 /resources/faq.php http://deanchiropractic.com/faq/
Redirect 301 /resources/articles/low-back-pain-relief.php http://deanchiropractic.com/low-back-pain-relief/
Redirect 301 /resources/articles/about-the-activator-method.php http://deanchiropractic.com/achieve-wellness-with-the-activator-method/
Redirect 301 /resources/articles/spinal-disc-treatment.php http://deanchiropractic.com/spinal-disc-treatment/
Redirect 301 /resources/articles/headache-relief-benefits.php http://deanchiropractic.com/headache-relief/
Redirect 301 /resources/articles/carpal-tunnel-relief.php http://deanchiropractic.com/carpal-tunnel-relief/
Redirect 301 /resources/articles/neck-pain-relief.php http://deanchiropractic.com/neck-pain-relief/
Redirect 301 /testimonials.php http://deanchiropractic.com/reviews/
Redirect 301 /contact.php http://deanchiropractic.com/contact-us/
Redirect 301 /about/ http://deanchiropractic.com/about-us/
Redirect 301 /techniques/ http://deanchiropractic.com/chiropractic-techniques/
Redirect 301 /community/ http://deanchiropractic.com/get-healthy/
Redirect 301 /resources/ http://deanchiropractic.com/forms/
Redirect 301 /resources/articles/ http://deanchiropractic.com/category/articles/
# 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
我搜索过广泛,并且在这个网站上找不到我确切问题的匹配...虽然我在这个过程中学到了很多关于.htaccess的知识(仍然是n00b tho)。感谢....
答案 0 :(得分:0)
mod_alias和mod_rewrite可能互相干扰,因为它们都应用于处理管道中的同一个URL。在这种情况下,可能是URI被更改并且重定向被mod_alias标记(通过Redirect
指令)但是然后mod_rewrite执行其操作并重写URI以通过index.php
进行路由,但是URI被标记为重定向,因此在管道的末尾,您有一个被修改的URI作为重定向发送。您可以通过坚持使用mod_rewrite并使用L
标志来避免这种情况,因此不会应用wordpress规则:
RewriteEngine On
RewriteRule ^/?about/dr-dean.php http://deanchiropractic.com/about-us/christophe-dean-dc/ [L,R=301]
RewriteRule ^/?about/dr-jon.php http://deanchiropractic.com/about-us/dr-jon-dean/ [L,R=301]
RewriteRule ^/?techniques/activator.php http://deanchiropractic.com/chiropractic-techniques/activator-method/ [L,R=301]
等...