2012-11-08 52 views
0

我想重写一个简单的URL,但不会产生谷歌的错误重写规则错误

此代码:

RewriteEngine on 
RewriteRule lieu/([0-9]+).* index.php?com=location&lID=$1 [L] 
RewriteRule evenement/([0-9]+).* index.php?eID=$1 [L] 

,但我想加上R = 301标志SEO

当我添加[R = 301,L]:

The requested URL /var/www/mysite/index.php was not found on this server. 

我知道R = 301标志必须以http使用://

但是当我尝试的网址并非rewritting

+0

当然这个目标URL不是有效的URL。这是一个服务器路径(目录路径)。 – Madbreaks

+0

@Madbreaks确定,但你有什么建议? – bklups

+0

请向我们展示您的完整重写块,其中包括301 – Madbreaks

回答

0

阿帕奇试图猜测一个路径是URI路径或文件路径,它猜错。当你在内部重写时,文件路径非常好,因为它全部在服务器内部。但是当你重定向时,apache错误地猜测你的目标(index.php?eID=)是一个文件路径,它被标记为由mod_alias作为重定向处理。到重定向发生时,它的格式变为文件路径而不是URI路径。这就是为什么当你重定向时你得到了/var/www/mysite/位。

要么添加RewriteBase为相对URI提供一个URI的基础,或者使你的目标绝对URI:

RewriteEngine On 
RewriteBase/
RewriteRule lieu/([0-9]+).* index.php?com=location&lID=$1 [R=301,L] 
RewriteRule evenement/([0-9]+).* index.php?eID=$1 [L,R=301] 

RewriteEngine on 
RewriteRule lieu/([0-9]+).* /index.php?com=location&lID=$1 [L,R=301] 
RewriteRule evenement/([0-9]+).* /index.php?eID=$1 [L,R=301] 
+0

我没有这个错误/ var/www/mysite /),但只要添加R = 301标志,URL不会更改。它只与唯一的L标志 – bklups

+0

链接是好的,但没有出现在浏览器的地址栏 – bklups

+0

@bklups我忘了添加'R = 301'标志到第一条规则 –