htaccess使用查询参数对URL进行内部重写

乔治

我有一个php文件/var/www/somepath/index.php来处理请求

http://example.com/somepath/?q=query

我想要同一个文件来处理对

http://example.com/some/other/path/?q=query
http://example.com/another/path/?q=query
http://example.com/yet/another/path/?q=query

我不想将php文件复制到文件系统中的多个位置。我认为使用内部重写规则将是一种更好的方法。这是我放在顶级.htaccess文件中的内容/var/www/.htaccess

RewriteRule ^some/other/path /somepath/%{QUERY_STRING} [PT]

但这是行不通的。我收到http://example.com/some/other/path/?q=query的404

我知道启用了mod_rewrite是因为我在相同的.htaccess文件中具有外部重写规则(301和302重定向),并且这些规则有效。

阿努巴瓦

您可以将此规则作为第一个规则放在站点根目录.htaccess中,该站点将处理带有?q=查询参数的任何URL

RewriteEngine On

RewriteCond %{QUERY_STRING} (^|&)q= [NC]
RewriteRule ^ somepath/index.php [L]

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章