假设我有一个旧网址http://abc.com/x.php?a=xyz&b=jkl我需要将所有请求重定向到x.php页面,或者将查询字符串重定向到http://xyz.com/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]
答案 0 :(得分:0)
在文档根目录的htaccess文件中,添加以下规则:
RewriteEngine On
RewriteRule ^/?x.php$ /x/? [L,R=302]
请注意,如果您有将/x/
重写回 /x.php
的规则,这两条规则将发生冲突并导致内部循环。您可以通过包含:
RewriteCond %{ENV:REDIRECT_STATUS} !200
正好在上面RewriteRule
。