2015-07-13 261 views
3

重寫動態URL後無法重定向。.htaccess動態URL重定向

動態URL:http://localhost/amploutargetsharing/campaigninfo.php?unique_hash=f5f386e

重定向後,我想要的網址看起來像下面。

所需的URL:http://localhost/amploutargetsharing/f5f386e

正如我google一下,寫下面的代碼。

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

但我想要的網址看起來像上述所需的URL。

+0

可能重複http://stackoverflow.com/questions/30591437/ htaccess-rewrite-to-remove-query-string) – CBroe

+0

是的,這是一個真正的目錄Anubhava爵士 –

回答

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] 
[htaccess的重寫刪除查詢字符串(的
+1

先生,非常感謝你的親切幫助你的代碼真的很好。:) :) –

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] 
+0

其不工作的兄弟.. :( –

+1

你是什麼意思「它不工作」? – starkeen

+0

@Starkeen先生,代碼我得到一個e 找不到對象! 在此服務器上找不到請求的URL。推薦頁面上的鏈接似乎是錯誤或過時的。請通知該頁面的作者關於錯誤。 如果您認爲這是服務器錯誤,請與網站管理員聯繫。 錯誤404 本地主機 星期二07月14 8點43分26秒2015 阿帕奇/ 2.2.14(UNIX)DAV/2的mod_ssl/2.2.14的OpenSSL/0.9.8l PHP/5.3.1的mod_perl/2.0.4的Perl /v5.10.1 和新的URL變成這樣。 http:// localhost/Applications/XAMPP/xamppfiles/htdocs/amploutargetsharing/amploutargetsharing/f5f386e –