0

假设我有一个旧 URL http://abc.com/x.php?a=xyz&b=jkl我需要将所有请求重定向到页面 x.php 有查询字符串或没有到http://xyz.com /X/

以下是http://xyz.com根目录中的 .htaccess 文件

# 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]
4

1 回答 1

0

在文档根目录的 htaccess 文件中,添加以下规则:

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

请注意,如果您有规则要重写/x/ /x.php,这两个规则将发生冲突并导致内部循环。您可以通过包含以下内容来防止循环:

RewriteCond %{ENV:REDIRECT_STATUS} !200

就在上面RewriteRule

于 2012-10-12T21:37:49.150 回答