簡體   English   中英

.htaccess 301重定向Apache

[英].htaccess 301 redirect Apache

我真的很難使用此重寫規則

RewriteRule ^index.php?a=profile&u=(.*)$ /profile/$1 [R=301]

我想像mysite.com/profile/USERNAME一樣進行301重定向

Querystring不是RewriteRule中match的一部分,您需要在RewriteCond中與%{THE_REQUEST} var進行匹配,然后使用%n獲得該匹配:

這應該是您完整的htaccess:

RewriteEngine on
RewriteCond %{THE_REQUEST} /index\.php\?a=profile&u=([^\s]+) [NC]
RewriteRule ^ /profile/%1? [L,R]
RewriteRule ^profile/([^/]+)/?$ /index.php?a=profile&u=$1 [NC,L]

嘗試

RewriteCond %{QUERY_STRING} ^a=profile&u=(.*)$
RewriteRule ^index.php /profile/%1 [L,R]

暫無
暫無

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

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