Renamed directories to sub-domain

Good day,

I have CMS with SEO friendly URL rewrite enabled that generates URLs lets say www.domain.com/urllevel1/urllevel2

And I have created sub-domain lets say sub1.domain.com

Now, I want some of these generated URLs (example www.domain.com/urllevel1/...etc) to be browsed as sub1.domain.com/urllevel1/...etc

Any idea?

Best regards,
Ahmed.

Ahmed,

Sure! Since a subdomain is normally “pointed” at a subdirectory of the domain, it’s safe to simply use mod_rewrite in the domain’s .htaccess to check for the existance of the urllevel1 directory then redirect to HTTP://SUB1.domain.com (with the remainder of the original URI after urllevel1/ has been removed).

Regards,

DK

Thank DK for the prompt response! what you have said is exactly what I’m looking for…

Currently, in my domain root .htaccess I have the follow rules to enable the SEO URLs

<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME}/index.html !-f
RewriteCond %{REQUEST_FILENAME}/index.php !-f
RewriteRule . index.php [L]
</IfModule> 

What do I need to add here in order to achieve my theory?

Thanks in advance,
A

Hi tata2,

No problem, mate!

Comments on your code:

<IfModule mod_rewrite.c>

[color=red][standard rant #4][indent]The definition of insanity is to repeatedly do the same thing expecting 
a different result.  Asking Apache to confirm the existence of ANY module with an 
<IfModule> ... </IfModule> wrapper is the same thing in the webmaster world.  
DON'T ACT INSANE!  If you don't know whether a module is enabled, run the 
test ONCE (without the wrapper) then delete it permanently as it is EXTREMELY 
wasteful of Apache's resources (and should NEVER be allowed on a shared 
server).[/indent][/standard rant #4]

Uh, simply test once to see whether your mod_rewrite is enabled then delete the <IfModule> and </IfModule> wrapper code.[/color]

RewriteEngine On
RewriteBase /

[color=red]Remove this as it's just plain not needed (and can confuse you if you have a mod_alias redirection).[/color]

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} /index.html !-f

[color=red]Don't forget the space after the variable you're testing against - then remove the leading / 
for Apache 2.x servers (and escape the dot character in the regex).[/color]

RewriteCond %{REQUEST_FILENAME} /index.php !-f

[color=red]Ditto the above.[/color]

RewriteRule . index.php [L]

[color=red]What about the domain-only request? You've required a single character (the / doesn't count) 
so you've got to rely on the DirectoryIndex to request index.php. Use a ? after the dot (optional character) so the regex will ALWAYS be true and the redirection will take effect.[/color]

</IfModule> 

[color=red]As above.[/color]

What do I need to add here in order to achieve my theory?

Is this what your new CMS requires? If so, IMMEDIATELY after the RewriteEngine on …

# in domain.com's Document Root (so sub1.domain.com can't access it)

# redirect to HTTP://SUB1.domain.com (with the remainder of the original URI after urllevel1/ has been removed)

RewriteRule ^subdir1/(.*)$ http://sub1.domain.com/$1 [R=301,L]

# Here, you DO want to capture the entire URI [i]after[/i] the subdir so (.*) 
will do that for you and the domain change will prevent looping.

Regards,

DK

Thanks dklynn!

The

RewriteRule ^subdir1/(.*)$ http://sub1.domain.com/$1 [R=301,L]

did the trick and redirected my virtual pages to the sub-domain.

However, it gave me 500 error everytime I browse any of the links or endless loop

For better understanding on what’s going go

Please login to the test environment located here www.artinglow.net

Username: guest
Password: guest123

Click on “Section” this should take you to www.artinglow.net/section/ but after applying the rewrite rule as follows:

RewriteRule ^section/(.*)$ http://section.artinglow.net/$1 [R=301,L]

It will show you http://section.artlinglow.net

and the same should go for “Sub-section”…

Now, to bring the actual pages up…and remove these errors…

Best regards,
A

Hi tt2!

Glad to hear that it’s working for you … but the question you’ve asked makes me wonder:

Regards,

DK