2
我的URL看起来像http://example.com/?n=x
。我希望URL显示为http://example.com/
。我已经习惯了迄今为止的做法,但都没有成功。无法使用.htaccess从URL中删除查询字符串
第一种是基于this question:
RewriteEngine On RewriteCond %{QUERY_STRING} ^n=1$ RewriteRule (.*) $1? [R=permanent]
后我下面的回答修改的.htaccess文件:
```RewriteEngine On
RewriteCond %{QUERY_STRING} ^n=(.*)$
RewriteRule (.*) $1? [R=permanent]```
,但它仍然没有奏效。下面是调试信息:
RewriteCond %{QUERY_STRING} ^n=(.*)$
This condition was met.
RewriteRule (.*) $1? [R=permanent]
The new url is http://example.com/blog/cat/??
Test are stopped, a redirect will be made with status code permanent
第二种方法是:
RewriteEngine On RewriteCond %{QUERY_STRING} !^$ RewriteRule ^(.*)$ $1 [QSD]
- 如果网址不手工输入是否只重写工作?
- 我仍然可以访问PHP中查询字符串的值吗?
- 当用户复制重写的URL时会发生什么?如果你去
http://example.com/?n=1
,如果我是正确的,你应该改变^n=1$
到^n=(.*)$
他们都不似乎工作。
我有几个问题:
感谢您的回答@ P0IT10n URL仍然没有被重写。 –
尝试在'RewriteEngine On'和'RewriteCond%{QUERY_STRING}^n =(。*)$','RewriteBase /' – matiaslauriti
之间添加如果仍然无法正常工作,请尝试查看您的'.htaccess'是否已被读取。使用[this](http://htaccess.mwl.be/)来尝试HTACCESS规则 – matiaslauriti