2010-11-18 157 views
2

我想縮短htaccess的縮短網址

www.site.com/product/info/laptop到www.site.com/laptop

我用

RewriteRule ^(.+)$ /product/info/$1 

但我得到500內部服務器錯誤

當我嘗試,

RewriteRule ^([a-zA-Z0-9_\s\'~%,:!?()_=&-]+)$ /product/info/$1 

它的作品,但我想支持這個時期,所以當我包括。

RewriteRule ^([a-zA-Z0-9_\s\'~%,:!?()\._=&-]+)$ /product/info/$1 

它給了我500內部服務器錯誤

你能解釋一下這是怎麼回事?

謝謝

+0

爲什麼雙引號?表達式應該是[a-zA-Z0-9_ \ s \'〜%,:!?()\ ._ =& - ] + – 2010-11-18 05:33:11

回答

0

嘗試以下操作:

RewriteCond %{REQUEST_URI} ^/product/info/(.*)$ 
RewriteRule ^(.*)?$  /%2     [R=301,L] 

將在瀏覽器重定向www.example.com/product/info/laptop用「感動到www.example.com/laptop永久性「標題。

如果你的意思是你想的更短的URL指向長URL內部,則必須避免循環重定向:

RewriteRule ^product/info/.*$ -    [L] # don't redirect again 
RewriteRule ^(.*)$   /product/info/$1 [L] # redirect everything else 

第一線將停止嘗試重定向www.example.com/product/ info/laptop到www.example.com/product/info/product/info/laptop,等等。

編輯

基於您的評論,它看起來像你也試圖重定向除了IMG公司的phpmyadmin,等等一切,無論指數 - ?你都有點現在重新安排,有些東西像這樣:

RewriteEngine on 

RewriteCond %{REQUEST_URI} ^/(index\.php|img|phpmyadmin|images|user|wmd|FCKeditor|map|jscalendar|aurigma|xajax_js|css|js|include|floatbox|helper|styles|ajax|robots\.txt|favicon\.ico|product/info/(.*)) 
RewriteRule ^(.*)$ - [L] # don't redirect these 

RewriteRule ^(.*)$ /product/info/$1 # redirect everything else 

我不是第一次重寫的「product/info /(.*)」部分的100%。如果還是不行,請嘗試以下:

RewriteEngine on 

RewriteCond %{REQUEST_URI} ^/(index\.php|img|phpmyadmin|images|user|wmd|FCKeditor|map|jscalendar|aurigma|xajax_js|css|js|include|floatbox|helper|styles|ajax|robots\.txt|favicon\.ico) 
RewriteRule ^(.*)$ - [L] # don't redirect these 

RewriteRule ^product/info/.*$ -    [L] # don't redirect again 

RewriteRule ^(.*)$ /product/info/$1 [L] # redirect everything else 

編輯2

最終的答案基於您的評論:

RewriteEngine on 
RewriteCond %{REQUEST_URI} ^/(index\.php|img|phpmyadmin|images|user|wmd|FCKeditor|map|jscalendar|aurigma|xajax_js|css|js|include|floatbox|helper|styles|ajax|robots\.txt|favicon\.ico) 
RewriteRule ^(.*)$ - [L] # don't redirect these 

# pass controllers to index.php 
RewriteCond %{REQUEST_URI} ^/(home|browse|calendar|star|member|enter|product) 
RewriteRule ^(.*)$ /index.php?$1 [L] 

# pass other things than controllers to /index.php?/product/info/$1 
RewriteRule ^(.*)$ /index.php?/product/info/$1 [L] # redirect everything else 
+0

非常感謝您的幫助。我希望較短的網址指向長URL內部,所以我的htaccess現在看起來像 – user257867 2010-11-18 06:28:24

+0

RewriteEngine敘述上 的RewriteCond%{REQUEST_URI}^/產品/信息/(.*)$ 重寫規則^產品/信息/。 * $ - #不再重定向 RewriteRule ^(。*)$/product/info/$ 1#重定向一切 RewriteCond $ 1!^(index \ .php | img | phpmyadmin | images | user | wmd | FCKeditor |地圖| jscalendar | aurigma | xajax_js | css | js |包括| floatbox |助手|款式|阿賈克斯|機器人\ .TXT |圖標\。ICO) 重寫規則^(*)$ /index.php?$1 [L] 但現在這給了我 服務器錯誤! 服務器遇到內部錯誤,無法完成您的請求。服務器超載或出現錯誤。 – user257867 2010-11-18 06:28:46

+0

我已經更新了上面的答案 - 您需要保留這些[L]的位置,否則它將繼續處理更多規則。 – 2010-11-18 21:28:40