我有這樣的規則.htaccess
:用於重寫規則的.htaccess
RewriteRule ^([^/]*)$ /user.php?username=$1 [L]
輸出:
http://domain.tld/username
所需的輸出:
http://domain.tld/user/username
我怎樣才能做到這一點?
我有這樣的規則.htaccess
:用於重寫規則的.htaccess
RewriteRule ^([^/]*)$ /user.php?username=$1 [L]
輸出:
http://domain.tld/username
所需的輸出:
http://domain.tld/user/username
我怎樣才能做到這一點?
這裏是如何改變一個URL的查詢字符串的路徑:
RewriteEngine On
RewriteCond %{REQUEST_URI} ^/user.php [NC]
RewriteCond %{QUERY_STRING} ^.*username=([a-zA-Z]+).*$ [NC]
RewriteRule ^(.*)$ /user/%1? [L]
輸入
http://domain.tld/user.php?username=bob
輸出
http://domain.tld/user/bob
這裏是如何走另一條路:
RewriteEngine On
RewriteCond %{REQUEST_URI} ^/user/ [NC]
RewriteRule ^user/(.+)$ /user.php?username=$1 [L]
輸入
http://domain.tld/user/bob
輸出
http://domain.tld/user.php?username=bob
你可以測試.htaccess
規則在這裏:http://htaccess.madewithlove.be/
輸入是http:// domain.tld/user.php?username = bob,輸出是http:// domain.tld/user/bob?或以其他方式? – Drakes