簡體   English   中英

htaccess縮短網址

[英]htaccess shortening url

我想縮短

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

我用了

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

但我收到500 Internal Server Error

當我嘗試時

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

它有效,但我也想支持該期限,所以當我包括時。

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

它給了我500 Internal Server Error

你能解釋發生了什么嗎?

謝謝

請嘗試以下操作:

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

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM