[英]Modify .htaccess to make URL?variable=true change to URL/variable?
我試圖更改我的.htaccess文件,以便如果我轉到:
http://www.example.com/index.php?login=true
,它轉到http://www.example.com/login
。
我目前擁有刪除index.php的代碼(使上面的代碼看起來像http://www.example.com/?login=true
)。
RewriteEngine On
#remove index.php
RewriteCond %{THE_REQUEST} ^GET.*index\.php [NC]
RewriteCond %{THE_REQUEST} !/system/.*
RewriteRule (.*?)index\.php/*(.*) /$1$2 [R=301,L]
RewriteCond %{THE_REQUEST} ^GET
我會以另一種方式設置您的重寫規則:
RewriteEngine On
RewriteRule ^login$ /index.php?login=true
這樣,如果用戶瀏覽到http://yourserver.com/login,則實際使用的頁面是http://yourserver.com/index.php?login=true ,但是第一個URL在瀏覽器中顯示。 我認為這就是您要實現的目標。
如果您確實需要按照要求的方向進行操作,可以嘗試執行以下操作:
RewriteEngine on
RewriteCond %{QUERY_STRING} ^login=true$
RewriteRule ^index\.php$ /login [L,R=301]
這將失敗,因為還有其他查詢參數。
如果您要將http://yourserver.com/index.php重定向到http://yourserver.com ,則只需添加以下重寫規則:
RewriteRule ^index\.php$ / [L,R=301]
盡管排除/ system / *的行可能存在問題,但以下內容應該可以工作。 嘗試測試注釋掉的內容。
RewriteEngine On
RewriteCond %{QUERY_STRING} ([^=]*)=true [NC]
RewriteCond %{THE_REQUEST} ^/system/.*
RewriteRule index.php /%1? [R=301,L]
以下頁面提供了幫助: http : //wiki.apache.org/httpd/RewriteQueryString
這個測試器很酷,但是確實有一些錯誤: http : //martinmelin.se/rewrite-rule-tester/
您需要在RewriteCond中檢查QUERY_STRING。 我認為應該這樣做:
RewriteEngine On
#remove index.php
RewriteCond %{QUERY_STRING} ([^=]*)=true [NC]
RewriteCond %{THE_REQUEST} !/system/.*
RewriteRule ^index\.php /%1? [R=301,L]
這應該將具有index.php?= true的任何內容重定向到/ action
在example.com的根目錄中的.htaccess中嘗試以下操作
RewriteEngine On
RewriteBase /
#rewrite http://www.example.com/anything to http://www.example.com/index.php?anything=true
RewriteCond %{REQUEST_URI} ^/([-a-zA-Z0-9]+)$ [NC]
RewriteCond %1 !system [NC]
RewriteRule . index.php?%1=true [L]
#301 redirect requests for example.com/index.php?anything=true to example.com/anything
RewriteCond %{REQUEST_URI} ^/index\.php$ [NC]
RewriteCond %{QUERY_STRING} ^([^=]+)=true$ [NC]
RewriteRule . /%1? [L,R=301]
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.