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