php - mod_rewrite 和带有参数的完整 url 作为参数

标签 php regex apache .htaccess mod-rewrite

我想获得带有参数的完整url到index.php,用mod_rewrite重写

.htaccess

RewriteEngine On
RewriteBase /
RewriteCond %{DOCUMENT_ROOT}%{REQUEST_FILENAME} !-f
RewriteCond %{DOCUMENT_ROOT}%{REQUEST_FILENAME} !-d
RewriteRule (.*)$ index.php?q=$1 [L,QSA]

仅index.php

print_r($_GET);

当我尝试时

domain.tld/http://asdf/asdf&s=1%3fb=3&c=34

我明白了

Array
(
    [q] => http://asdf/asdf
    [s] => 1?b=3
    [c] => 34
)

但我需要这样的东西:

Array
(
    [q] => http://asdf/asdf&s=1%3fb=3&c=34 //some complicated url
)

有什么(简单的)方法吗?我找到了许多针对不同参数的解决方案,而不是一体化的解决方案。 抱歉我的英语:)

最佳答案

您可以在根 .htaccess 中使用此规则:

RewriteEngine On

RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{THE_REQUEST} \s/+(\S+)
RewriteRule ^ /index.php?q=%1 [B,L]

关于php - mod_rewrite 和带有参数的完整 url 作为参数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22155678/

相关文章:

php - 从 Codeigniter 导出 CSV 文件

php - 无法在mysql中添加子查询别名

php - 如何将选定值从选择框传递到研究

apache - 当我发布新版本的网站时,为什么我的用户看不到最新更新?

java - 如何在 Apache Web 服务器上运行 Grails 应用程序 WAR 文件?

php - SQL查询: how to make the parents without children?

python - 为什么我的正则表达式可以在 regexr.com 上运行,但从命令行运行时会抛出错误?

c - 为什么 C 的 regexec() 不匹配此模式,但 javascript 的 match() 有效?

javascript - 在 Angular 中从 URL 中解析参数

apache - 在生产中无法访问 Flask-Admin 页面