2012-10-12 174 views
0

讓說我有一箇舊的URL http://abc.com/x.php?a=xyz&b=jkl我需要重定向所有的請求頁面x.php既可以採用具有查詢字符串或不http://xyz.com/x/302 htaccess的從舊的PHP頁面重定向到新的URL

下面是的.htaccess文件,該文件是存在於http://xyz.com

# Turn on URL rewriting 
RewriteEngine On 

RewriteBase/

# Protect application and system files from being viewed 
RewriteRule ^(application|modules|system) - [F,L] 

# Allow any files or directories that exist to be displayed directly 
RewriteCond %{REQUEST_FILENAME} !-f 
RewriteCond %{REQUEST_FILENAME} !-d 
RewriteCond $0 !=server-status 


# Rewrite all other URLs to index.php/URL 
RewriteRule .* index.php/$0 [PT,L] 

回答

0

在你的文檔根htaccess文件根目錄,添加下列規則:

RewriteEngine On 
RewriteRule ^/?x.php$ /x/? [L,R=302] 

注ŧ如果你有規則重寫/x/返回/x.php,這兩條規則會衝突並導致內部循環。您可以通過包含以下內容來防止循環:

RewriteCond %{ENV:REDIRECT_STATUS} !200 

右上方的上述RewriteRule

+0

我的網址與http://abc.com/test/index.php?a=xyz&b=jkl一樣,我希望將此網址重定向到http://abc.com/test/我正在切換到基於框架的網站從簡單的PHP網站。 –

+0

@SushantPrasad和你想要重定向到什麼? (你爲什麼不剛纔問這個問題?) –

+0

你的代碼正在重定向到指定的URL/x /,但它顯示500內部服務器錯誤 服務器遇到內部錯誤或配置錯誤,無法完成請求。 –

相關問題