简体   繁体   English

500 Internal Server Error with RewriteRule,从旧目录重定向到新目录

[英]500 Internal Server Error with RewriteRule, redirecting from old directory to new directory

I'm sorry, I know there are a million mod_rewrite questions on here already. 抱歉,我知道这里已经有百万个mod_rewrite问题。 I looked through a good many and tried to learn from others' mistakes, but I don't see what I'm doing wrong here. 我浏览了很多,试图从别人的错误中学习,但是我看不到我在做什么错。

My site used to be at http://example.com/andrew/qa . 我的网站曾经位于http://example.com/andrew/qa Now it's at http://example.com/fdso . 现在位于http://example.com/fdso

I just want to redirect all /andrew/qa/(.*) URLs to /fdso/$1 . 我只想将所有/andrew/qa/(.*)重定向到/fdso/$1 Including changing the URL on the browser, which I understand the 301 option takes care of: 据了解,包括更改浏览器中的URL,301选项可解决以下问题:

DirectoryIndex index.php
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_URI} ^/andrew/qa/.* [NC]
RewriteRule ^/andrew/qa/(.*)$ /fdso/$1 [L,301]
</IfModule>

I have this in a .htaccess file at /andrew/qa/.htaccess. 我在/andrew/qa/.htaccess中的.htaccess文件中有此文件。

I'm getting a 500 Internal Server Error and can't figure out why. 我收到500个内部服务器错误,无法弄清原因。

And the server I'm on does not seem to generate logs for some reason. 而且由于某种原因,我所在的服务器似乎未生成日志。 (The logs directory is missing.) I have very little control over this server, as I don't have root access. (缺少logs目录。)由于我没有超级用户访问权限,因此对该服务器几乎没有控制权。

This line is causing 500 error: 此行导致500错误:

RewriteRule ^/andrew/qa/(.*)$ /fdso/$1 [L,301]

It is because 301 should be R=301 . 这是因为301应该是R=301

However your rule will still not redirect because of a leading / and presence of /andrew/qa/ in RewriteRule pattern. 但是,由于RewriteRule模式中的前导//andrew/qa/存在,您的规则仍然不会重定向。

Have it this way in /andrew/qa/.htaccess : /andrew/qa/.htaccess有这种方式:

RewriteEngine On

RewriteRule ^(.*)$ /fdso/$1 [L,NE,R=301]

You also don't need redundant RewriteCond . 您也不需要冗余的RewriteCond

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM