![](/img/trans.png)
[英]htaccess, redirect from old page to new page (php and post variable)
[英]302 htaccess redirect from old php page to new url
假設我有一個舊網址http://abc.com/x.php?a=xyz&b=jkl我需要將所有請求都重定向到具有查詢字符串或不具有http://xyz.com的頁面x.php。 /X/
以下是.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]
在文檔根目錄的htaccess文件中,添加以下規則:
RewriteEngine On
RewriteRule ^/?x.php$ /x/? [L,R=302]
請注意,如果您有規則將/x/
改寫回 /x.php
,則這兩個規則將發生沖突並導致內部循環。 您可以通過以下方式防止循環:
RewriteCond %{ENV:REDIRECT_STATUS} !200
就在上面的RewriteRule
上方。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.