Forum Moderators: phranque

Message Too Old, No Replies

prevent subdomain from redirecting to domain

involves index.php

         

youfoundjake

1:06 am on Dec 27, 2007 (gmt 0)

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



Howdie Jim,
I just created a new subdomain.
url structure is [joomla.example.com...]
When I go to log in, I am of course redirected to http://www.example.com/joomla/ and again prompted with the login
My current .htaccess looks simple.
RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /([^/]+/)*index\.php\ HTTP/
RewriteRule ^(([^/]+/)*)index\.php$ http://www.example.com/$1 [R=301,L]
#
RewriteCond %{HTTP_HOST} ^example\.com [NC]
RewriteRule (.*) http://www.example.com/$1 [R=301,L]

I have a blog on the TLD, which uses index.php, and my Joomla installation on the subdomain uses index.php.

I tried playing around with the ReWrite, and specifically put in the subdomain, but I'm still getting redirected. I know that cPanel has an option to redirect a folder, but I don't wanna get stuck in a 301 loop.
Also, all this is on top of the Wordpress Rewrite that is in the .htaccess file

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

I'm thinking that I should probably put a .htaccess in the subdomain directory with this in it.


RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /([^/]+/)*joomla.example.com\index\.php\ HTTP/
RewriteRule ^(([^/]+/)*)index\.php$ [joomla.example.com...] [R=301,L]

Make sense?

youfoundjake

1:20 am on Dec 27, 2007 (gmt 0)

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



Ok,
Options +FollowSymlinks
RewriteEngine on
RewriteBase /
#
RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /([^/]+/)*example.com\index\.php\ HTTP/
RewriteRule ^(([^/]+/)*)index\.php$ [joomla.example.com...] [R=301,L]

I placed that in a new .htaccess file in the subdomain
The above is working, and I'm able to log in to the admin panel, just not redirecting index.php to subdomain, but I'll get it, maybe.

jdMorgan

1:28 am on Dec 27, 2007 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



To retain the index.php-to-slash redirect, but preserve the original subdomain, you could use:

RewriteCond %{HTTP_HOST}<>%{THE_REQUEST} ^([a-z]+\.)?example./com(:[0-9]+)?<>[A-Z]{3,9}\ /([^/]+/)*index\.php\ HTTP/
RewriteRule ^(([^/]+/)*)index\.php$ http://%1example.com/$1 [R=301,L]

Note, however, that you will get a chained redirect if, for example, http://example.com/index.php is requested. This is because this rule leaves the domain as-is, so the second redirect will kick in after this first redirect is done, and add "www" to the originally-requested "example.com" domain.

To suppress the index-to-www.example.com/ redirect for the joomla subdomain only, just add a RewriteCond to your original rule to deactivate it if the joomla subdomain is requested:


RewriteCond %{HTTP_HOST} !^joomla\.example\.com
RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /([^/]+/)*index\.php\ HTTP/
RewriteRule ^(([^/]+/)*)index\.php$ http://www.example.com/$1 [R=301,L]

As a last option, you could use two index-redirect rules, one for joomla, and another for anything-else-but-joomla:


RewriteCond %{HTTP_HOST} ^joomla\.example\.com
RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /([^/]+/)*index\.php\ HTTP/
RewriteRule ^(([^/]+/)*)index\.php$ http://joomla.example.com/$1 [R=301,L]
#
RewriteCond %{HTTP_HOST} !^joomla\.example\.com
RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /([^/]+/)*index\.php\ HTTP/
RewriteRule ^(([^/]+/)*)index\.php$ http://www.example.com/$1 [R=301,L]

Pick one, depending on what you want.

Jim

[edited by: jdMorgan at 1:29 am (utc) on Dec. 27, 2007]

youfoundjake

2:16 am on Dec 27, 2007 (gmt 0)

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



I would imagine that I'm placing the
RewriteCond %{HTTP_HOST}!^joomla\.example\.com
RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /([^/]+/)*index\.php\ HTTP/
RewriteRule ^(([^/]+/)*)index\.php$ http://www.example.com/$1 [R=301,L]

in the TLD .htaccess file? How does that get processed if the request is to the subdomain?

youfoundjake

3:47 am on Dec 27, 2007 (gmt 0)

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



Jim, I'm running Windows XP
Do you think I can run Apache 2.059 on it? Might as well install to learn faster eh?

jdMorgan

4:31 am on Dec 27, 2007 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



> How does that get processed if the request is to the subdomain?

That depends on how you've got the subdomain mapped to your filespace. If you used code in your top-level .htaccess to accomplish the mapping, then all code in that .htaccess file gets executed, regardless of the requested hostname. If you used a control panel, then maybe that code will get executed and maybe it won't -- Control Panel functions vary, and I can't answer questions about the configuration code they produce unless I can see the code.

You can install Apache under XP. Windows support is much improved in Apache 2.x. Just make sure you get all the additional 'pieces' you need to test your site(s), such as PERL, PHP, mySQL, etc. Most people are happiest using one of the 'packaged' installation solutions, such as WAMP or XAMPP, etc. These save you from having to compile all the modules separately and get everything linked-in -- a challenge even for an Apache/*nix expert.

Jim

youfoundjake

8:00 pm on Jan 1, 2008 (gmt 0)

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



Jim, thanks for the tip. I went ahead and installed WAMP, give me a week to figure out php, apache, and MYSQL, and then you can put my name next to yours as a forum moderator. heeh, j/k, give me 2 weeks.
Happy Holidays.