2012-10-15 111 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

相關問題