htaccess的URL重写问号 [英] htaccess url rewrite with question mark

查看:508
本文介绍了htaccess的URL重写问号的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个问题,的.htaccess ,特别是关于重定向。

I'm having a problem in .htaccess, specifically on redirection.

我想改写这个网址:

http://www.domain.com/?mod=country

http://www.domain.com/country

我已经尝试过这种的.htaccess code:

RewriteEngine on
RewriteRule ^\?mod=(.*)$ $1

我试图做这个工作,没有问号字符,它工作正常。 我躲过了问号,因为它的特殊字符的一部分,不过,我无法得到它的工作。

I tried working on it without the question mark character and it works fine. I have escaped the question mark because it's part of the special characters, but still, I couldn't get it work.

你能告诉我缺少的是什么?

Can you tell what I'm missing?

推荐答案

直接翻译你的要求重写规则:

Directly translating your requirements to rewrite rules:

RewriteEngine On
RewriteCond %{QUERY_STRING} ^mod=(.*)$
RewriteRule ^$ %1

但你可能想要的东西更灵活,如:

But you probably want something more flexible like:

RewriteEngine On
RewriteCond %{QUERY_STRING} (?:^|&)mod=([^&]+)
RewriteRule /?(.*) %1/$1 [QSA]

这些规则适用于你的域的根。

These rules apply to the root of your domain.

如果你想要做一个外部重定向添加研究标志重写规则。

If you want to do an external redirect add the R flag to the rewrite rule.

这篇关于htaccess的URL重写问号的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆