2012-10-15 75 views
2

sombody可以帮我这个问题,我尝试使用htaccess文件重新直接一个页面,但它一直到新网址的末尾添加?c=oldpage,例如:htaccess的添加查询字符串301重定向

http://www.mydomain.co.uk/newpage.html?c=oldpage 

我已经尝试了一些张贴在这里的解决方案,但没有运气的,这里是我的.htaccess文件:

DirectoryIndex index.php index.html index.htm  
Options +FollowSymLinks  
RewriteEngine on  
RewriteCond %{QUERY_STRING} PHPSESSID=.*$  
RewriteRule (.*) http://www.mydomain.co.uk/$1? [R=301,L]  
RewriteCond %{HTTP_HOST} ^mydomain.co.uk$ [NC]  
RewriteRule ^(.*)$ http://www.mydomain.co.uk/$1 [R=301,L]  
RewriteCond %{THE_REQUEST} /index\.php\ HTTP/  
RewriteRule ^index\.php$/[R=301,L]  
RewriteEngine on  
RewriteRule ^product/(.*).html$ product.php?p=$1 [L]  
RewriteRule ^(.*)\.html$ category.php?c=$1 [L,NC]   

Redirect 301 /oldpage.html http://www.mydomain.co.uk/newpage.html  

ErrorDocument 404 /404.php 

感谢您的帮助。

回答

0
RewriteEngine on 
RewriteCond %{HTTP_HOST} ^abc\.net$ [OR] 
RewriteCond %{HTTP_HOST} ^www\.abc\.net$ 
RewriteRule ^example\.html$ "http\:\/\/abc\.net\/example\/" [R=301,L] 
RewriteOptions inherit 

到一个文件夹,或:

RewriteEngine on 
RewriteCond %{HTTP_HOST} ^abc\.net$ [OR] 
RewriteCond %{HTTP_HOST} ^www\.abc\.net$ 
RewriteRule ^example\.html$ "http\:\/\/abc\.net\/example\.html$" [R=301,L] 
RewriteOptions inherit 

不很了解,但它是我用的东西,希望它帮助。

+0

感谢您的回复,没有任何这方面的运气IM - 我咬了我的深度 – Chris

1

这是mod_alias(Redirect指令)和mod_rewrite不能很好地相互播放。因为这两个模块都将它们的指令应用于URL文件映射管道中的相同URI,所以它们不知道互相忽略,因为这两个指令都不知道其他模块正在做什么。由于你的目标重叠,两个模块都在相同的URI上应用它们的指令,并且你得到一个混杂的结果。

您需要mod_rewrite的坚持在这种情况下,与移动内部重写上面的重定向:

DirectoryIndex index.php index.html index.htm  
Options +FollowSymLinks  
RewriteEngine on  

# redirects 
RewriteCond %{QUERY_STRING} PHPSESSID=.*$  
RewriteRule (.*) http://www.mydomain.co.uk/$1? [R=301,L]  

RewriteCond %{HTTP_HOST} ^mydomain.co.uk$ [NC]  
RewriteRule ^(.*)$ http://www.mydomain.co.uk/$1 [R=301,L]  

RewriteCond %{THE_REQUEST} /index\.php\ HTTP/  
RewriteRule ^index\.php$/[R=301,L]  

RewriteRule ^oldpage.html$ http://www.mydomain.co.uk/newpage.html [R=301,L] 

# internal rewrites 
RewriteRule ^product/(.*).html$ product.php?p=$1 [L]  
RewriteRule ^(.*)\.html$ category.php?c=$1 [L,NC]   

ErrorDocument 404 /404.php 
+0

排序感谢您! – Chris

相关问题