2015-05-09 84 views
1

我需要在/ test/v1 /文件夾中將localhost/test/v1/rates等所有url重定向到api.php,並在/ test/v1 /文件夾中調用localhost/test/v2/rates給api.php。 v2 /文件夾(MAMP服務器)本地主機上的htaccess mod_rewrite

<IfModule mod_rewrite.c> 
RewriteEngine On 
RewriteBase /test/ 
RewriteRule ^index\.php$ - [L] 
RewriteCond %{REQUEST_FILENAME} !-f 
RewriteCond %{REQUEST_FILENAME} !-d 
RewriteRule ./v1/(.*)$ /test/v1/api.php?request=$1 [QSA,NC,L] 
</IfModule> 

之前的代碼不起作用。我剛剛用盡了幾乎所有的可能性。

請寄給我正確的方向。

+0

記住RewriteRule'的'第一個參數是一個正則表達式。 '。/ something'作爲正則表達式沒有任何意義。找出你正在匹配的是什麼。在'.htaccess'上下文中,'.htaccess'文件所在的文件夾將從您匹配的url中刪除。該網址永遠不會以'/'開頭。 – Sumurai8

回答

-1

如果您使用的是RewriteBase /test/,則必須將該目錄添加到規則中,如 RewriteRule ^/test/index\.php$ - [L]

請勿使用./作爲入口點。

+0

列出'.htaccess'。在'.htaccess'文件中'RewriteRule'的第一個參數是從未用'/'開頭的url進行測試,因爲'.htaccess'文件夾被作爲前綴刪除,然後重新添加。 – Sumurai8

0

試試這個

<IfModule mod_rewrite.c> 
RewriteEngine On 
RewriteBase /test/ 
RewriteRule ^index\.php$ - [L] 
RewriteCond %{REQUEST_FILENAME} !-f 
RewriteCond %{REQUEST_FILENAME} !-d 
RewriteRule ^v1/(.*)/?$ /test/v1/api.php?request=$1 [QSA,NC,L] 

RewriteRule ^v2/(.*)/?$ /test/v2/api.php?request=$1 [QSA,NC,L] 
</IfModule> 


</IfModule> 
+1

非常感謝你的作品 –