簡體   English   中英

.htaccess刪除頁面並保留查詢

[英].htaccess remove the page and leave the query

我想改變

http://example/index.php?name = phone

http:// example / phone

我嘗試了這個:

RewriteRule ^([a-zA-Z0-9_-]+)$ index.php?name=$1
RewriteRule ^([a-zA-Z0-9_-]+)/$ index.php?name=$1

它實際上允許我使用example/phone但是當我使用example/index.php?name=phone時,我並不想強制重定向,我只希望能夠進入干凈的URL。 當我編寫非干凈網址時,應將我重定向到干凈網址。

編輯

我將嘗試簡化問題。 我想寫的是

example / index.php?name = phone

它將我重定向到

例子/電話

當然,“ phone”是一個變量。

干得好 :

  RewriteEngine On
  RewriteRule ^([^/]*)$ /index.php?name=$1 [L]

這有效:

RewriteEngine on

RewriteBase /

RewriteCond %{THE_REQUEST} ^[A-Z]{3,}\s/+index\.php\?name=([^\s]+) [NC]
RewriteRule ^ %1? [R=301,L]

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d

RewriteRule ^([a-zA-Z0-9_-]+)$ index.php?name=$1

RewriteRule ^([a-zA-Z0-9_-]+)/$ index.php?name=$1

暫無
暫無

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

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