Forum Moderators: phranque

Message Too Old, No Replies

redirect all request of subfolder

using a separate htaccess in subfolder

         

phparion

7:52 am on Apr 21, 2008 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



Hi

I have a website which uses rewrite rules. I have installed now a blog under /blog/ directory. Blog uses its own htaccess for SE friendly URLs. So i have written the following rule in my main site htaccess as the first rule,

RewriteRule ^blog/*$ /blog/$1 [L]

now the main website rules works fine but the blog urls give 500 internal server error.

any help is highly appreciated.

thank you

wheelie34

11:46 am on Apr 21, 2008 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Hi

try this, it works for me to redirect ALL from folder a to the root of folder b

RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /a/*
RewriteRule (.*) http://www.example.com/b/ [R=301,L]

jdMorgan

12:17 pm on Apr 21, 2008 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



In both posts above, the regular-expressions pattern contains "/*". Be aware that the meaning of that sub-pattern is "any number of slashes, including zero". That is not likely what was intended.

In addition, the rule in the first post internally rewrites requests for "/blog" followed by and ending with any number of slashes, to "/blog/" followed by an undefined path. Again, this is not likely what was intended, and at best, would rewrite "/blog/" to itself, creating an infinite loop.

Jim

phparion

8:38 pm on Apr 21, 2008 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



@J, i also tried RewriteRule ^/blog/(.*)$ /blog/$1 [L]

it worked for the exact page names but for urls like www.example.com/blog/blogadmin/

it gives internal error 500..

what do you suggest?

jdMorgan

9:59 pm on Apr 21, 2008 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



If that code is in httpd.conf, then it will rewrite all /blog/ URLs to themselves repeatedly, causing an "infinite" loop, and resulting in a server error.

If that code is in example.com/.htaccess it shouldn't do anything at all.

When you get a 500-Server Error, go look at your server error log; It's often quite helpful.

Jim

jdMorgan

10:05 pm on Apr 21, 2008 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



If your purpose is to by-pass all rules in example.com/.htaccess when example.com/blog/<anything> is requested, then the proper form for the first rule in example.com/.htaccess would be:

RewriteRule ^blog/ - [L]

That says, "If the requested URL-path starts with "blog/" then leave the URL-path unchanged, and stop processing mod_rewrite rules in this file."

Jim

[edited by: jdMorgan at 10:05 pm (utc) on April 21, 2008]

phparion

8:03 am on Apr 22, 2008 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



/blog - [L] worked perfect. thank you very much for wise words and help.