开发者

htaccess shortening url

i would like to shorten

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

I used

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

but i get 500 Internal Server Error

when i try,

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

it works but i want to support the period as well, so when I include .

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

It gives me 500 开发者_StackOverflowInternal Server Error

Could you explain what is going on?

Thank you


Try the following:

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

That will redirect the browser from www.example.com/product/info/laptop to www.example.com/laptop with a "Moved Permanently" header.

If you mean you wish the shorter URL to point to the longer URL internally, then you must avoid circular redirections:

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

The first line will stop trying to redirect www.example.com/product/info/laptop to www.example.com/product/info/product/info/laptop, and so-on.

Edit

Based on your comment, it looks like you're also trying to redirect everything except img, phpmyadmin, etc, to index?whatever - You have to rearrange it all a bit now, something like this:

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

I'm not 100% on the "product/info/(.*)" part of the first rewrite. If that doesn't work, try this:

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

Edit 2

Final answer based on your comment:

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

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜