2010-07-22 25 views
0

我想實現這個在基於smarty的網站上重寫URL?

example.com/search_results/?action=search&username[equal]=PorscheSA 

example.com/PorscheSA 

我用的.htaccess許多網站實現這一點,但由於該網站是基於Smarty的,它似乎並沒有工作。任何幫助都感激不盡。

好吧,這是.htaccess文件:

RewriteCond %{HTTP_HOST} ^www.example.com [NC] 
RewriteRule ^(.*)$ http://example.com/$1 [L,R=301] 

Options +FollowSymlinks 
RewriteEngine on 

RewriteCond %{REQUEST_FILENAME} !-d 
RewriteCond %{REQUEST_FILENAME} !-f 
RewriteRule .* ./index.php 

爲了實現以下我嘗試這樣做:

RewriteRule ^([a-zA-Z0-9-_+^/])/$ /search_results/?action=search&username[equal]=$1 

什麼都沒有發生。

+0

基於smarty的網站與htaccess/RewriteRules無效無關。你必須更詳細地描述你的設置和你想達到的目標。 – pocketfullofcheese 2010-07-22 05:39:49

回答

1

你的問題仍然有點模糊,因爲你已經發布了你的.htaccess,所以我會試一試它,看看我是否能得到你想要的結果。

RewriteRule不起作用的最明顯的原因是您的測試模式與您提供的URL作爲示例不匹配,因爲您的RewriteRule需要一個尾部斜線(並且只匹配一個字符) 。此外,如果您將其放在.htaccess文件中的規則之後,它將永遠不會匹配,因爲請求已被重寫爲index.php

我認爲你想這樣的事情...

Options +FollowSymlinks 

RewriteEngine on 

RewriteCond %{HTTP_HOST} =www.example.com [NC] 
RewriteRule ^.*$ http://example.com/$0 [L,R=301] 

# Make sure we end and force the redirect so %{REQUEST_FILENAME} gets changed 
RewriteRule ^[a-zA-Z0-9-_+^/]+$ search_results/?action=search&username[equal]=$0 [L] 

RewriteCond %{REQUEST_FILENAME} !-d 
RewriteCond %{REQUEST_FILENAME} !-f 
RewriteRule .* index.php 

但是,如果search_results/目錄不存在,那麼這僅僅是將改寫爲index.php反正,所以我不確定在這種情況下重定向的目的是什麼。而且,如果它確實存在,由於您的測試模式與我期望在網站路徑中看到的幾乎相同,因此所有內容都將被重寫爲search_results/目錄,因此很少(如果有的話)最終會在您的網站根目錄index.php

基於此,我覺得也許還有其他一些標準可能會遺漏,但我可能是錯的。