homepage Welcome to WebmasterWorld Guest from 54.204.141.129
register, free tools, login, search, pro membership, help, library, announcements, recent posts, open posts,
Pubcon Platinum Sponsor 2014
Visit PubCon.com
Home / Forums Index / Code, Content, and Presentation / Apache Web Server
Forum Library, Charter, Moderators: Ocean10000 & incrediBILL & phranque

Apache Web Server Forum

    
How NOT to redirect?
subdomain --> domain
JoshS




msg:1502808
 9:53 pm on Dec 7, 2005 (gmt 0)

Hi,

About a week ago I converted my main site from shtml files to php. I used url rewrite to redirect old links to the correct, new files, but it seams to have affected my subdomain...it now directs to my main site.

Is there something I can add to the htaccess file in the subdomain directory to make it dissregard the htaccess file in the root directory?

RewriteEngine Off has no affect.

I can post the contents of the root .htaccess file, if needed.

Thanks!

subdomain: [sub.domain.com...]

ends up at...

main site: [domain.com...]

 

jdMorgan




msg:1502809
 10:10 pm on Dec 7, 2005 (gmt 0)

Typically, you'd use RewriteConds to define the conditions under which you do and do not wish to redirect. However, if RewriteEngine off is having no effect, then it doesn't sound like it's your rewriterules causing the problem. Possibly, your host has changed the way that your domain aliases (ServerAliases) are handled.

Jim

JoshS




msg:1502810
 10:58 pm on Dec 7, 2005 (gmt 0)

Ok...I've got a ticket in to my host...so far, they are stumped.

Thanks!

jdMorgan




msg:1502811
 11:27 pm on Dec 7, 2005 (gmt 0)

Feel free to post a few snippets of your relevant filetype rewrite code in the meantime if you feel there's any possibility that it is the cause.

Jim

JoshS




msg:1502812
 11:39 pm on Dec 7, 2005 (gmt 0)

RedirectMatch 301 (.*)\.shtml$ [domain.com$1.php...]

That's it. I'm sure it is my lack of knowledge about this...

jbgilbert




msg:1502813
 12:19 am on Dec 8, 2005 (gmt 0)

This may work for you:

Options +FollowSymLinks
RewriteEngine on
RewriteCond %{HTTP_HOST}!^subdomain\.domain\.com
rewriterule (.*) [domain.com$1.php...] [R=permanent,L]

says if not asking for subdomain.domain.com, then
redirect according to rewriterule

JoshS




msg:1502814
 12:43 am on Dec 8, 2005 (gmt 0)

That returns a 500 Internal Server Error for the main site and subdomain...and yes, I did edit the rule with my domain :)

I have a section in my htaccess to keep bad bots out...would it matter that there are 2 Rewriteengine on in the file? Or the order they appear?

jbgilbert




msg:1502815
 2:01 am on Dec 8, 2005 (gmt 0)

josh,

post you full .htaccess file so I can see it (change domain names to dummies)

JoshS




msg:1502816
 2:39 am on Dec 8, 2005 (gmt 0)

Ok...here it is...

RedirectMatch 301 (.*)\.shtml$ http://www.example.com$1.php

RedirectMatch journal/archives/(.*) http://www.example.com/journal/archives.php

Redirect permanent /phpBB/index.php http://www.example.com/phpBB2/index.php
Redirect permanent /forum/ http://www.example.com/phpBB2/
Redirect permanent /phpBB/ http://www.example.com/phpBB2/
RedirectMatch permanent ^/design/index.html$ http://www.example.com/design/index.php
Redirect permanent /gallery_hostas_01.php http://www.example.com/gallery/hostapictures
Redirect permanent /gallery_hostas_02.php http://www.example.com/gallery/hostapictures
Redirect permanent /gallery_hostas_03.php http://www.example.com/gallery/hostapictures
Redirect permanent /gallery_hostas_04.php http://www.example.com/gallery/hostapictures
Redirect permanent /gallery_hostas_05.php http://www.example.com/gallery/hostapictures
Redirect permanent /gallery_hostas_06.php http://www.example.com/gallery/hostapictures
Redirect permanent /gallery_hostas_07.php http://www.example.com/gallery/hostapictures
Redirect permanent /gallery_hostas_landscape_01.php http://www.example.com/gallery/hostapictures
Redirect permanent /gallery_pond_01.php http://www.example.com/gallery/pondpictures
Redirect permanent /gallery_pond_02.php http://www.example.com/gallery/pondpictures
Redirect permanent /gallery_pond_03.php http://www.example.com/gallery/pondpictures
Redirect permanent /gallery_pond_04.php http://www.example.com/gallery/pondpictures
Redirect permanent /christmas2001.shtml http://www.example.com/christmas.php
Redirect permanent /christmas2002.shtml http://www.example.com/christmas.php
Redirect permanent /christmas2003.shtml http://www.example.com/christmas.php
Redirect permanent /christmas2004.shtml http://www.example.com/christmas.php
Redirect permanent /xmasnewsletter2001.shtml http://www.example.com/xmasnewsletter2001_2.php
Redirect permanent /xmasnewsletter2001.php http://www.example.com/xmasnewsletter2001_2.php
Redirect permanent /xmasnewsletter2002.php http://www.example.com/xmasnewsletter2002_2.php
Redirect permanent /xmasnewsletter2002.shtml http://www.example.com/xmasnewsletter2002_2.php

ErrorDocument 404 /404.php

<Limit GET>
Order Allow,Deny
Allow from all
Deny from example.net
</Limit>

<Files 403.shtml>
order allow,deny
allow from all
</Files>

deny from 200.**.19.98
# <snip>
deny from 68.**.56.132

php_value zend_optimizer.optimization_level 14

RewriteEngine On
RewriteCond %{HTTP_USER_AGENT} ^BlackWidow [OR]
RewriteCond %{HTTP_USER_AGENT} ^Bot\ mailto:craftbot@yahoo.com [OR]
RewriteCond %{HTTP_USER_AGENT} ^ChinaClaw [OR]
RewriteCond %{HTTP_USER_AGENT} ^Custo [OR]
RewriteCond %{HTTP_USER_AGENT} ^DISCo [OR]
RewriteCond %{HTTP_USER_AGENT} ^Download\ Demon [OR]
RewriteCond %{HTTP_USER_AGENT} ^eCatch [OR]
RewriteCond %{HTTP_USER_AGENT} ^EirGrabber [OR]
RewriteCond %{HTTP_USER_AGENT} ^EmailSiphon [OR]
RewriteCond %{HTTP_USER_AGENT} ^EmailWolf [OR]
RewriteCond %{HTTP_USER_AGENT} ^Express\ WebPictures [OR]
RewriteCond %{HTTP_USER_AGENT} ^ExtractorPro [OR]
RewriteCond %{HTTP_USER_AGENT} ^EyeNetIE [OR]
RewriteCond %{HTTP_USER_AGENT} ^FlashGet [OR]
RewriteCond %{HTTP_USER_AGENT} ^GetRight [OR]
RewriteCond %{HTTP_USER_AGENT} ^GetWeb! [OR]
RewriteCond %{HTTP_USER_AGENT} ^Go!Zilla [OR]
RewriteCond %{HTTP_USER_AGENT} ^Go-Ahead-Got-It [OR]
RewriteCond %{HTTP_USER_AGENT} ^GrabNet [OR]
RewriteCond %{HTTP_USER_AGENT} ^Grafula [OR]
RewriteCond %{HTTP_USER_AGENT} ^HMView [OR]
RewriteCond %{HTTP_USER_AGENT} HTTrack [NC,OR]
RewriteCond %{HTTP_USER_AGENT} ^Image\ Stripper [OR]
RewriteCond %{HTTP_USER_AGENT} ^Image\ Sucker [OR]
RewriteCond %{HTTP_USER_AGENT} Indy\ Library [NC,OR]
RewriteCond %{HTTP_USER_AGENT} ^InterGET [OR]
RewriteCond %{HTTP_USER_AGENT} ^Internet\ Ninja [OR]
RewriteCond %{HTTP_USER_AGENT} ^JetCar [OR]
RewriteCond %{HTTP_USER_AGENT} ^JOC\ Web\ Spider [OR]
RewriteCond %{HTTP_USER_AGENT} ^larbin [OR]
RewriteCond %{HTTP_USER_AGENT} ^LeechFTP [OR]
RewriteCond %{HTTP_USER_AGENT} ^Mass\ Downloader [OR]
RewriteCond %{HTTP_USER_AGENT} ^MIDown\ tool [OR]
RewriteCond %{HTTP_USER_AGENT} ^Mister\ PiX [OR]
RewriteCond %{HTTP_USER_AGENT} ^Navroad [OR]
RewriteCond %{HTTP_USER_AGENT} ^NearSite [OR]
RewriteCond %{HTTP_USER_AGENT} ^NetAnts [OR]
RewriteCond %{HTTP_USER_AGENT} ^NetSpider [OR]
RewriteCond %{HTTP_USER_AGENT} ^Net\ Vampire [OR]
RewriteCond %{HTTP_USER_AGENT} ^NetZIP [OR]
RewriteCond %{HTTP_USER_AGENT} ^Octopus [OR]
RewriteCond %{HTTP_USER_AGENT} ^Offline\ Explorer [OR]
RewriteCond %{HTTP_USER_AGENT} ^Offline\ Navigator [OR]
RewriteCond %{HTTP_USER_AGENT} ^PageGrabber [OR]
RewriteCond %{HTTP_USER_AGENT} ^Papa\ Foto [OR]
RewriteCond %{HTTP_USER_AGENT} ^pavuk [OR]
RewriteCond %{HTTP_USER_AGENT} ^pcBrowser [OR]
RewriteCond %{HTTP_USER_AGENT} ^RealDownload [OR]
RewriteCond %{HTTP_USER_AGENT} ^ReGet [OR]
RewriteCond %{HTTP_USER_AGENT} ^SiteSnagger [OR]
RewriteCond %{HTTP_USER_AGENT} ^SmartDownload [OR]
RewriteCond %{HTTP_USER_AGENT} ^SuperBot [OR]
RewriteCond %{HTTP_USER_AGENT} ^SuperHTTP [OR]
RewriteCond %{HTTP_USER_AGENT} ^Surfbot [OR]
RewriteCond %{HTTP_USER_AGENT} ^tAkeOut [OR]
RewriteCond %{HTTP_USER_AGENT} ^Teleport\ Pro [OR]
RewriteCond %{HTTP_USER_AGENT} ^VoidEYE [OR]
RewriteCond %{HTTP_USER_AGENT} ^Web\ Image\ Collector [OR]
RewriteCond %{HTTP_USER_AGENT} ^Web\ Sucker [OR]
RewriteCond %{HTTP_USER_AGENT} ^WebAuto [OR]
RewriteCond %{HTTP_USER_AGENT} ^WebCopier [OR]
RewriteCond %{HTTP_USER_AGENT} ^WebFetch [OR]
RewriteCond %{HTTP_USER_AGENT} ^WebGo\ IS [OR]
RewriteCond %{HTTP_USER_AGENT} ^WebLeacher [OR]
RewriteCond %{HTTP_USER_AGENT} ^WebReaper [OR]
RewriteCond %{HTTP_USER_AGENT} ^WebSauger [OR]
RewriteCond %{HTTP_USER_AGENT} ^Website\ eXtractor [OR]
RewriteCond %{HTTP_USER_AGENT} ^Website\ Quester [OR]
RewriteCond %{HTTP_USER_AGENT} ^WebStripper [OR]
RewriteCond %{HTTP_USER_AGENT} ^WebWhacker [OR]
RewriteCond %{HTTP_USER_AGENT} ^WebZIP [OR]
RewriteCond %{HTTP_USER_AGENT} ^Wget [OR]
RewriteCond %{HTTP_USER_AGENT} ^Widow [OR]
RewriteCond %{HTTP_USER_AGENT} ^WWWOFFLE [OR]
RewriteCond %{HTTP_USER_AGENT} ^Xaldon\ WebSpider [OR]
RewriteCond %{HTTP_USER_AGENT} ^Zeus
RewriteRule ^.* - [F,L]

I'm sure there are many mistakes!

[edited by: jdMorgan at 5:41 am (utc) on Dec. 8, 2005]
[edit reason] Removed/obscured specific IPs, examplified. [/edit]

jdMorgan




msg:1502817
 5:36 am on Dec 8, 2005 (gmt 0)

> This may work <better> for you:

Options +FollowSymLinks
RewriteEngine on
RewriteCond %{HTTP_HOST} !^subdomain\.example\.com
RewriteRule (.*) http://www.example.com/$1.php [R=301,L]

(The space between "}" and "!" was missing, and is absolutely required. Posting on this board deletes spaces preceding "!" characters, unfortunately. Also, for use in .htaccess, the substitution changes slightly; Note the slash after ".com"

Jim

jbgilbert




msg:1502818
 3:19 pm on Dec 8, 2005 (gmt 0)

As usual JD to the rescue...

Thanks for catching that. Josh, let us know if it works.

JoshS




msg:1502819
 3:56 pm on Dec 8, 2005 (gmt 0)

No go. Firefox gives me this error:

The page isn't redirecting properly

Firefox has detected that the server is redirecting the request for this address in a way that will never complete.

I get this for the main and sub domains.

And the urls look like this:

main: www.domain.com/.php.php.php.php. (and on and on...)

sub: www.domain.com/index.php.php.php.php. (and on and on...)

jdMorgan




msg:1502820
 4:28 pm on Dec 8, 2005 (gmt 0)

".shtml" got dropped somewhere in this thread, so this should work better:

Options +FollowSymLinks
RewriteEngine on
RewriteCond %{HTTP_HOST} !^subdomain\.example\.com
RewriteRule ([^.]+)\.shtml$ http://www.example.com/$1.php [R=301,L]

Jim

JoshS




msg:1502821
 5:02 pm on Dec 8, 2005 (gmt 0)

Main domain functions normally, but the sub still redirects.

To complicate things even more, sub.domain.com/index.php works fine. It is only without the index.php that it redirects to the main site.

I really appreciate the time you're taking, here!

jdMorgan




msg:1502822
 7:42 pm on Dec 8, 2005 (gmt 0)

Sounds like two things are going on:
1) Your server has UseCanonicalName set to 'on'
2) You have not defined the DirectoryIndex page expcicitly.

In this case, failing to find a page at sub.domain.com, mod_dir on the server generates a redirect which may be kicking it over to www.domain.com instread of sub.domain.com.

Try explicitly declaring your directory index page by adding

DirectoryIndex index.php

to your .htaccess file.

I'm not sure that will help, but it's the only thing I can think of. Otherwise, I'd suggest you contact your host and ask them why a specific URL in the subdomain is getting redirected to the main domain. If they can't help, then ask them to please e-mail you the httpd.conf file for the server (they'll want to remove the confing info for all other sites hosted on that server if it's shared, but that's fine).

Something's not right with your configuration, but it's hard to tell what without access to the config file.

Jim

JoshS




msg:1502823
 8:01 pm on Dec 8, 2005 (gmt 0)

DirectoryIndex index.php

That did it! Thank you for your help...I *really* appreciate it!

biggles




msg:1502824
 2:41 am on Dec 13, 2005 (gmt 0)

Hi Jim

I have a slightly different version of the problem you were able to sort out for JoshS. Hope you can tell me where I'm going wrong please.

I have a sub-domain (subdomain-b/mydomain.co.uk) that I want to re-direct to another domain (domain-b.co.uk).

Have tried the following but it doesn't work.

RewriteCond %{HTTP_HOST} .
RewriteCond %{HTTP_HOST} ^subdomain-b\.mydomain\.co\.uk
RewriteRule (.*) [domain-b.co.uk...] [R=301,L]

Any advice you can give will be appreciated.

Thanks very much.

jdMorgan




msg:1502825
 3:06 am on Dec 13, 2005 (gmt 0)

There's nothing at all wrong with your code, so it's down to a couple of questions:

1) Is this code located in a directory-path that will be accessed when the subdomain is requested? If not, then it can have no effect. (If you have defined the subdomain using a "control panel" then it is likely that you'll need to move this code into an .htaccess file in the subdirectory created by the control panel to house the files for the subdomain.)

2) Do you have other working rewriterules in the same .htaccess file? If so, then that proves that your server is configured to process mod_rewrite code.

Other than that, I can't think of anything else without knowing more about specifically how "it doesn't work."

Jim

biggles




msg:1502826
 10:00 am on Dec 13, 2005 (gmt 0)

Thanks for the prompt reply Jim. Appreciated.

I didn't have the .htaccess file in the subdirectory which contains the files used by the subdomain. So have copied the .htaccess file & moved it there as you advised. However still no joy. (Path to directory with subdomain files being: /var/www/directory)

By it 'not working' what I meant is that [subdomain-b...] doesn't re-direct to www.domain-b.co.uk which is what I'm trying to achieve. Instead the site is presented with the URL [subdomain-b...]

To answer the other point you raised. Yes, I do have other rewrite rules working in the same .htaccess file? So that proves the server is configured to process mod_rewrite code.

One thing I didn't mention is that its a site that uses FrontPage extensions, so not sure if that's a factor.

Would it help to sticky you the actual htaccess file?

Thanks.

jdMorgan




msg:1502827
 3:04 pm on Dec 13, 2005 (gmt 0)

FrontPage extensions again... :(

In order for a site using FrontPage extensions to work with mod_rewrite, you must place the directive

Options +FollowSymLinks

in *every* .htaccess file on your site.

It replaces the directive

Options None

if present in these .htaccess files.

The FollowSymLinks option is required to enable mod_rewrite in each subdirectory.

As pointed out in another recent thread [webmasterworld.com], using PHP or SSI to replace FrontPage extensions would make your life easier on an Apache server.

Jim

biggles




msg:1502828
 12:31 pm on Dec 14, 2005 (gmt 0)

Jim

That worked. THANK YOU!

Global Options:
 top home search open messages active posts  
 

Home / Forums Index / Code, Content, and Presentation / Apache Web Server
rss feed

All trademarks and copyrights held by respective owners. Member comments are owned by the poster.
Home ¦ Free Tools ¦ Terms of Service ¦ Privacy Policy ¦ Report Problem ¦ About ¦ Library ¦ Newsletter
WebmasterWorld is a Developer Shed Community owned by Jim Boykin.
© Webmaster World 1996-2014 all rights reserved