Forum Moderators: phranque

Message Too Old, No Replies

Mod Rewrite - Folder

mod rewrite, folder, subdomains

         

mhamdi

4:46 am on Dec 7, 2006 (gmt 0)

10+ Year Member



Hi,
Can someone help me with this:

[#*$!.domain.com...] ==> [#*$!.domain.com...]
#*$!: any subdomain
yyy: any file in the folder dir

So basically I want to redirect all calls to /dir to / for all subdomains and all files in /dir

Thanks in advance!

mhamdi

4:50 am on Dec 7, 2006 (gmt 0)

10+ Year Member



Sorry for the double post but it looks like xx,x is misinterpreted here :) I replace it with zzz in the following

[zzz.domain.com...] ==> [zzz.domain.com...]
zzz: any subdomain
yyy: any file in the folder dir

jdMorgan

5:46 am on Dec 7, 2006 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Please post the code you're trying to get working, so we can discuss it.

For more information, please review our forum charter [webmasterworld.com].

Jim

mhamdi

6:13 am on Dec 7, 2006 (gmt 0)

10+ Year Member



This is all I could come up with, not working

RewriteCond %{REQUEST_URI} ^/blogs/
RewriteRule ^(.*)$ ../$1 [L]

I am complete noob in mod_rewrite.

jdMorgan

1:42 pm on Dec 7, 2006 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Assuming that you're on a shared virtual server and that this code goes into the top-level .htaccess file, I'd suggest:

RewriteRule ^blogs/(.*)$ http://%{HTTP_HOST}/$1 [R=301,L]

Here, we require the requested URL-path to start with "blogs/", record any URL-path which follows that (by putting parentheses around the ".*" subpattern). If the pattern matches, we redirect to the same requested hostname (i.e. domain), followed by that recorded URL-path ($1). The [R=301,L] flags indicate that this is a 301-Moved Permanently redirect, and that it should be done immediately without processing any additional rewriterules that might follow this one.

If you're on a dedicated server, then HTTP_HOST must be checked to be sure that it is not blank. If you put the code in a server configuration file, such as httpd.conf instead of .htaccess, then the rewriterule pattern must start with a slash. If you put the code into .htaccess in the '/blogs/' subdirectory itself, then you must omit "blogs/" from the rewriterule pattern.

For more information, see the documents cited in our forum charter [webmasterworld.com] and the tutorials in the Apache forum section of the WebmasterWorld library [webmasterworld.com].

Jim