簡體   English   中英

使用 htaccess 從 url 中刪除查詢字符串

[英]Remove the query string from url using htaccess

我需要一些有關 htaccess 的幫助。 你能幫點忙嗎? 我有一個這樣的網址

https://example.com/index.php?p=application-intelligence

[或者]

https://example.com/?p=application-intelligence

基本上 index.php 傳遞了一些參數“home”來知道要加載哪個頁面,即 home.php 所以我試圖關注你在你博客上的帖子,但運氣不佳。

所以我希望最終的代碼是

https://example.com/application-intelligence

這是我的代碼。

RewriteEngine on 
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^([^/]+)/?$ index.php?p=$1

也適用於https://example.com?p=home

我希望它只是

https://example.com

這是我的 apache 虛擬主機 conf 文件中的內容:

RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-l
RewriteRule ^(.*)$ index.php?$1 [L,QSA]

您可以使用以下規則:

RewriteEngine on

# handle /?p=home
RewriteCond %{THE_REQUEST} \s/+(?:index\.php)?\?p=home\s [NC]
RewriteRule ^ /? [R=301,L,NE]

# handle /?p=<something>
RewriteCond %{THE_REQUEST} \s/+(?:index\.php)?\?p=([^\s&]+) [NC]
RewriteRule ^ /%1? [R=301,L,NE]

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^([^/]+)/?$ index.php?p=$1 [L,QSA]

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM