重写后无法重定向动态网址。
动态网址:http://localhost/amploutargetsharing/campaigninfo.php?unique_hash=f5f386e
重定向后我希望URL看起来如下所示。
所需网址:http://localhost/amploutargetsharing/f5f386e
当我谷歌这个并写下面的代码。
RewriteEngine On
RewriteCond %{REQUEST_URI} ^/amploutargetsharing/campaigninfo\.php$
RewriteCond %{QUERY_STRING} ^unique_hash=([a-z0-9]*)$
RewriteRule ^(.*)$ http://localhost/amploutargetsharing/%1 [R,L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^([^/]+)/?$ campaigninfo.php?unique_hash=$1 [L,QSA]
以上代码给出了以下结果。
HTTP //本地主机/ amploutargetsharing / f5f386e?unique_hash = f5f386e
但我希望网址看起来像上面想要的网址。
答案 0 :(得分:1)
试试这个:
RewriteEngine On
RewriteCond %{THE_REQUEST} /amploutargetsharing/campaigninfo.php\?unique_hash=([^&\s]+) [NC]
RewriteRule ^ amploutargetsharing/%1? [NC,R,L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^([^/]+)/([^/]+)/?$ amploutargetsharing/campaigninfo.php?unique_hash=$2 [QSA,L,NC]
答案 1 :(得分:0)
在/amploutargetsharing/.htaccess
中尝试这些规则:
RewriteEngine On
RewriteBase /amploutargetsharing/
RewriteCond %{THE_REQUEST} /campaigninfo.php\?unique_hash=([^&\s]+) [NC]
RewriteRule ^ %1? [L,NE,R=302]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^([^/]+)/?$ campaigninfo.php?unique_hash=$1 [QSA,L]