apache - mod_rewrite 不适用于查询字符串重定向

标签 apache .htaccess mod-rewrite

目前,我有一个漂亮网址的重写规则,运行良好。我尝试添加一秒钟,但这给我带来了问题:

# 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 to domain.com/?p=test

试试这个:

Options +FollowSymlinks -MultiViews
RewriteEngine On
RewriteBase /
RewriteCond %{QUERY_STRING} !p=   [NC]
RewriteRule  ^([^/]+)/?   /?p=$1 [L,NC]

选项:

如果情况相反:
domain.com/?p=testdomain.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/

相关文章:

apache - 从 Vary header 中删除 X Forwarded-ssl(Apache 网络服务器)

python - 使用旧 python 版本的 mod_wsgi 运行时

.htaccess - 2 域名 (EN/FR) 1 FTP 重定向

regex - 如何使用 mod_rewrite 从旧的 php 脚本重定向到新的 php 脚本

.htaccess 将index.php重定向到home而不重定向子域

javascript - Magento 2 Wysiwyg TinyMCE编辑器弹出窗口想要下载htm文件

.htaccess - 在目录中停止 .htaccess mod_rewrite

python - 设置 mod_python 解释器

php - 无法访问 Live Server 中的 codeigniter Controller ,但可以在本地主机中访问(Windows 上的 xampp)

java - Lucene中如何获取以特定字母开头的记录