目前,我有一个漂亮网址的重写规则,运行良好。我尝试添加一秒钟,但这给我带来了问题:
# redirect /?p=xyz to /xyz
RewriteCond %{QUERY_STRING} ^p=(.*)$
RewriteRule ^(.*)$ /index.php/%1 [L]
# Removes index.php from ExpressionEngine URLs
RewriteCond $1 !\.(gif|jpe?g|png)$ [NC]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ /index.php/$1 [L]
第二个工作正常,但第一个给我内部服务器错误。基本上我希望 ?p=* 中的任何内容都转到/index.php/*
[编辑]为了澄清,我需要 http://domain.com/?p=test相当于 http://domain.com/test/
最佳答案
domain.com/test
todomain.com/?p=test
试试这个:
Options +FollowSymlinks -MultiViews
RewriteEngine On
RewriteBase /
RewriteCond %{QUERY_STRING} !p= [NC]
RewriteRule ^([^/]+)/? /?p=$1 [L,NC]
选项:
如果情况相反:
domain.com/?p=test
到 domain.com/test/index.php
试试这个:
Options +FollowSymlinks -MultiViews
RewriteEngine On
RewriteBase /
RewriteCond %{QUERY_STRING} p=([^/]+) [NC]
RewriteRule .* /%1/index.php? [L,NC]
删除index.php
,以防不需要,如下所示:
RewriteRule .* /%1/? [L,NC]
关于apache - mod_rewrite 不适用于查询字符串重定向,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15799020/