Forum Moderators: phranque

Message Too Old, No Replies

Apache Rewrite - NO case sensitivity

[NC] doesn't work..

         

atario

8:00 pm on Dec 22, 2009 (gmt 0)

10+ Year Member



Hi, i really have no clue what i'm doing, i'm just following tutorials. But [NC] doesn't work in this case.

What I really want is have www.mysite.com/blog to redirect to my subdomain blog.mysite.com. IT WORKS!

BUT, www.mysite.com/BLOG or if the cases do not match exactly to 'blog', then it'll be 404. Why is that?

I tried replacing [L,R=301] to [NC] or [L,R=301,NC] and stuff, no luck.. Any help would be fabulous, thanks in advance.

Options -Indexes +FollowSymLinks
RewriteEngine On
RewriteBase /
RewriteCond %{HTTP_HOST} ^mysite.com [NC]
RewriteRule ^(.*)$ [mysite.com...] [L,R=301]
RedirectMatch 301 ^/blog/(.*)$ [blog.mysite.com...]

g1smd

8:35 pm on Dec 22, 2009 (gmt 0)

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



There's problems if you use Redirect and RewriteRule in the same file.

The order the rules are processed is indeterminate, as rules are processed in 'per module' order, not in the order they appear on the page.

That is, all rules from Mod_Alias might be processed before all those from Mod_Rewrite - or maybe it is the other way round.

Stick with RewriteRule for all of your rules to avoid that problem, and order the rules from most specific to least specific.

atario

9:38 pm on Dec 22, 2009 (gmt 0)

10+ Year Member



thanks g1smd,

how should i rewrite it to make it work? I'm very new to this, i only know some syntax rules and that's about it.. rewriting from scratch wouldn't be my forte.

thanks in advance!

jdMorgan

1:33 am on Dec 23, 2009 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



As stated in our Forum Charter, we ask that you please do not request the contributors here to write your code for you -- If it's important to you, then please try to code it yourself and take the opportunity to learn something new.

That said, Merry Christmas! :


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

A review of the mod_rewrite and mod_alias documentation at apache.org would seem to be in order... RewriteRule and RedirectMatch directives are handled by different Apache modules, and their syntax and capabilities are different.

Note that the redirect target for the second rule has been changed in order to avoid multiple 'chained' redirects when "example.com" is requested.

Jim