簡體   English   中英

htaccess從網址中刪除index.php和參數名稱

[英]htaccess remove index.php and param name from url

我為網站提供短網址服務,該網站的網址如http://example.co?c=xyz 在index.php文件參數被訪問為$code = $_GET["c"];

當我輸入http://eaxample.co/xyz時,我想訪問相同的代碼

.htaccess文件配置

Options -Multiviews
Options +FollowSymLinks
RewriteEngine On
RewriteRule (.*) /$1? [R=301, L]

任何人都可以幫助我制定正確的規則嗎?

將此代碼放在您的DOCUMENT_ROOT/.htaccess文件中:

Options +FollowSymLinks -MultiViews
RewriteEngine On

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

如果需要,該查詢字符串將起作用,必須在您的重寫器中添加QSA標志。

當替換URI包含查詢字符串時,RewriteRule的默認行為是丟棄現有查詢字符串,並將其替換為新生成的查詢字符串。 使用[QSA]標志會使查詢字符串組合在一起。

Options -Multiviews
Options +FollowSymLinks
RewriteEngine On
RewriteRule (.*) /$1? [R=301, L, QSA]

暫無
暫無

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

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