【发布时间】:2016-10-25 05:12:58
【问题描述】:
我的网址看起来像http://example.com/?n=x。我希望 URL 显示为 http://example.com/。到目前为止我已经习惯了这些方法,但它们都不起作用。
-
第一个基于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]
它们似乎都不起作用。
我还有几个问题:
- 只有在不手动输入 URL 的情况下,重写才有效吗?
- 我还能在 PHP 中访问查询字符串的值吗?
- 当用户复制重写后的 URL 时会发生什么?
【问题讨论】:
标签: php .htaccess mod-rewrite