2011-04-28 46 views
1

這裏的參數創建htaccess的重寫規則(點或週期)是我的樣本網址:如何在URL

http://mydomain.com/folder/subfolder/index.php ?網站= www.othersite.com

我想這種方式重寫:

http://mydomain.com/folder/subfolder/www.othersite.com

我試着

RewriteEngine on 

RewriteBase /folder/subfolder/ 

RewriteRule ^([A-Za-z0-9\\-\\.]+)$ index.php?site=$1 [L] 

我打印數組$ _GET,並返回「的index.php」,它沒有返回「www.othersite.com」

這怎麼可能是「網站」參數的值做了什麼?

感謝,

+0

使用。在正則表達式中,你可以用\來轉義它。但在你的情況下,我沒有看到你的點問題。 – 2011-04-28 02:10:51

+0

RewriteRule ^([A-Za-z0-9 -_-] +)$ index.php?site = $ 1 [L] 如果參數'site'的值沒有(點或句點) – scoohh 2011-04-28 02:28:54

+0

對不起,我誤解了你的要求,並提供了相反的解決方案。請看下面的答案,它應該適合你。 – anubhava 2011-04-28 03:53:20

回答

0

試試這個規則.htaccess文件:

Options +FollowSymlinks -MultiViews 
RewriteEngine on 

RewriteCond %{QUERY_STRING} !^site= [NC] 
RewriteRule ^(folder/subfolder)/(.*)$ /$1/index.php?site=$2 [L,NC,QSA]