This forum has been moved here:
Helicon Tech Community Forum

ISAPI_Rewrite 3.0 (Forum Locked Forum Locked)
 Helicon Tech : ISAPI_Rewrite 3.0
Subject Topic: Generic Subdomain Redirect
Author
Message |
FairweatherWeb
Newbie


Joined: 16 November 2008
Location: United Kingdom
Posts: 22
Posted: 29 July 2011 at 9:06am

Chaps

I have seen a number of similar questions on the forum but nothing specific to my question.

I have a Website that uses a single handler file. It has a growing number of Sub Domains.

So I need a rule that leaves the URL the same...

http://subdomain.mydomain.com

...or...

http://www.mydomain.com/mypage

...but invisibly redirects to the file...

http://www.mydomain.com/myfile.aspx

...which pulls data from a Database. I don't want to have to update the httpd file each time a subdomain is added to the Database so I need a Generic redirect.

Cheers

Kevin



Edited by FairweatherWeb - 29 July 2011 at 9:18am


__________________
Regards
Kevin Russell
Fairweather Web LTD
Back to Top Visit FairweatherWeb's Homepage
 
Guests
Guest


Joined: 01 October 2003
Online Status: Online
Posts: -160
Posted: 02 August 2011 at 7:43am

Hello,

These issue are fully described in FAQ and examples section

Regards
Andrew
Back to Top
 
FairweatherWeb
Newbie


Joined: 16 November 2008
Location: United Kingdom
Posts: 22
Posted: 07 September 2011 at 6:03pm

Andrew

It must be me, but I cannot get the examples to work with both pages and subdomains.

Can anyone give me a [huge] hint?

Regards
Kevin


__________________
Regards
Kevin Russell
Fairweather Web LTD
Back to Top Visit FairweatherWeb's Homepage
 
Guests
Guest


Joined: 01 October 2003
Online Status: Online
Posts: -160
Posted: 08 September 2011 at 4:53am

Try using smth like:

RewriteEngine on
RewriteBase /

RewriteCond %{REQUEST_FILENAME}.asp -f
RewriteRule (.*) /$1.asp [NC,L]

Regards
Andrew
Back to Top
 
FairweatherWeb
Newbie


Joined: 16 November 2008
Location: United Kingdom
Posts: 22
Posted: 09 September 2011 at 10:40am

Andrew

Thanks for that - I don't seem to be seeing teh results I though.

http://test.localemergencylocksmiths.co.uk/

...I get a "Bad Request (Invalid Hostname)" error. Can I prove that it is actually working - I have had conffirmation that ISAPI_Rewrite is installed and active.

I pasted the code into a file called httpd.conf.

Cheers
Kevin


__________________
Regards
Kevin Russell
Fairweather Web LTD
Back to Top Visit FairweatherWeb's Homepage
 
Guests
Guest


Joined: 01 October 2003
Online Status: Online
Posts: -160
Posted: 12 September 2011 at 4:46am

Sorry, I haven't warned you that this rule is for the following scenario only:

Quote:
http://www.mydomain.com/mypage
...but invisibly redirects to the file...
http://www.mydomain.com/myfile.aspx


About the subdomain requests... please clarify what subdomains need to be directed? Where do they need to be directed?


Regards
Andrew
Back to Top
 
FairweatherWeb
Newbie


Joined: 16 November 2008
Location: United Kingdom
Posts: 22
Posted: 12 September 2011 at 4:51am

Andrew

Thanks for the reply, I think we are getting there!

I need a rule for two scenarios, one of which you have sort of done.

1) All pages to invisibly redirect to a single file

www.mydomain.com/page1
www.mydomain.com/page2
www.mydomain.com/page1/subpage3
www.mydomain.com/page1/subpage6

...to...

www.mydomain.com/index.aspx

2) All subdomains to go to the same file

sub1.mydomain.com/
sub1.mydomain.com/page1
sub1.mydomain.com/page1/subpage1

...to...

www.mydomain.com/index.aspx

basically, all traffic whatever the subdomain to be handled by the same file. There maybe some DNS setting required? Possible a wildcard subdomain.

Thanks again
Kevin


__________________
Regards
Kevin Russell
Fairweather Web LTD
Back to Top Visit FairweatherWeb's Homepage
 
FairweatherWeb
Newbie


Joined: 16 November 2008
Location: United Kingdom
Posts: 22
Posted: 13 September 2011 at 5:20am

Any ideas Andrew?

__________________
Regards
Kevin Russell
Fairweather Web LTD
Back to Top Visit FairweatherWeb's Homepage
 
Guests
Guest


Joined: 01 October 2003
Online Status: Online
Posts: -160
Posted: 13 September 2011 at 5:58am

The rule for the first case would look like:

Code:
#rewrite for the first and second level pages to index.aspx
RewriteEngine on
RewriteBase /

RewriteRule ^[^/]+/[^/]+$ /index.aspx [NC,L]


For the second case, please, try using:
Code:
# proxy tule for sub1.domain.com
RewriteCond %{HTTP:Host} ^sub1\.mydomain\.com$ [NC]
RewriteRule ^[^/]+/[^/]+$ http://www.mydomain.com/index.aspx [NC,P,L]


Regards
Andrew
Back to Top
 
FairweatherWeb
Newbie


Joined: 16 November 2008
Location: United Kingdom
Posts: 22
Posted: 13 September 2011 at 6:11am

Andrew

That's great. Just to confirm - this all goes into a file httpd.conf?

Kevin


__________________
Regards
Kevin Russell
Fairweather Web LTD
Back to Top Visit FairweatherWeb's Homepage
 
Guests
Guest


Joined: 01 October 2003
Online Status: Online
Posts: -160
Posted: 13 September 2011 at 6:20am

Yes. You may need the condition for the first rule, though. To avoid affecting all domains:

RewriteCond %{HTTP:Host} ^(?:www\.)?mydomain\.com$ [NC]
Back to Top
 
FairweatherWeb
Newbie


Joined: 16 November 2008
Location: United Kingdom
Posts: 22
Posted: 15 September 2011 at 8:06am

Andrew

Again - thanks for the tips.

I still get a Bad Request (Invalid Hostname) when accessing a subdomain. I have added the rules as .htaccess and httpd.conf just in case.

Do I need to create the subbdomain in DNS first?

Kevin


__________________
Regards
Kevin Russell
Fairweather Web LTD
Back to Top Visit FairweatherWeb's Homepage
 
Guests
Guest


Joined: 01 October 2003
Online Status: Online
Posts: -160
Posted: 15 September 2011 at 8:28am

Sure, you need DNS entries.

Regards
Andrew
Back to Top
 
FairweatherWeb
Newbie


Joined: 16 November 2008
Location: United Kingdom
Posts: 22
Posted: 16 September 2011 at 9:09am

Ok. How can I test if ISAPI_rewrite is running - none of my rules seem to be working although my host instists that it is running.

I need a basic rule I think


__________________
Regards
Kevin Russell
Fairweather Web LTD
Back to Top Visit FairweatherWeb's Homepage
 
Guests
Guest


Joined: 01 October 2003
Online Status: Online
Posts: -160
Posted: 19 September 2011 at 5:22am

It is described in FAQ
you need :
Code:
RewriteRule .? - [F]


Regards
Andrew
Back to Top
 
FairweatherWeb
Newbie


Joined: 16 November 2008
Location: United Kingdom
Posts: 22
Posted: 22 September 2011 at 9:14am

Thanks again for your help.

A page that doesn't end in a slash rewrites fine but a
page ending in a slash doesn't, it just fires a 404.

Works:
http://www.localemergencylocksmiths.co.uk/page/page1

Doesn't work
http://www.localemergencylocksmiths.co.uk/page/page1/

Code:

RewriteEngine on
RewriteBase /
RewriteRule ^[^/]+/[^/]+$ /index.asp [NC,L]

RewriteCond %{HTTP:Host}
^sub1\.localemergencylocksmiths\.co.uk$ [NC]
RewriteRule ^[^/]+/[^/]+$
http://www.localemergencylocksmiths.co.uk/index.asp
[NC,P,L]


Any help - most appreciated.
Kevin

__________________
Regards
Kevin Russell
Fairweather Web LTD
Back to Top Visit FairweatherWeb's Homepage
 
FairweatherWeb
Newbie


Joined: 16 November 2008
Location: United Kingdom
Posts: 22
Posted: 22 September 2011 at 10:15am

I added a rule to remove the trailing space and all is
well. I do have another ongoing issue though to finish
things off.

The subdomains rules doesn't seem to work.

I have added a subdomain in DNS called content and
pointed it to the www IP Address. Andrew provided me with
a rule for subdomains...

Code:
# proxy rule for sub1.domain.com
RewriteCond %{HTTP:Host}
^content\.localemergencylocksmiths\.co.uk$ [NC]
RewriteRule ^[^/]+/[^/]+$
http://www.localemergencylocksmiths.co.uk/index.asp
[NC,P,L]


...but I just get a Bad Request...

http://content.localemergencylocksmiths.co.uk/

...if I add the subdomain in the Hosting Control Panel
then I just get a Directory Listing Denied error. I just
need to capture this type of 404 as well

Any pointers gratefully received.
Kevin

Edited by FairweatherWeb - 22 September 2011 at 10:22am


__________________
Regards
Kevin Russell
Fairweather Web LTD
Back to Top Visit FairweatherWeb's Homepage
 
Guests
Guest


Joined: 01 October 2003
Online Status: Online
Posts: -160
Posted: 23 September 2011 at 6:50am

Regarding the trailing slassh... try using this one on top of the config file:

#Fix missing trailing slash char on folders
RewriteRule ^([^.?]+[^.?/])$ $1/ [R,L]

Regards
Andrew
Back to Top
 
FairweatherWeb
Newbie


Joined: 16 November 2008
Location: United Kingdom
Posts: 22
Posted: 05 October 2011 at 7:52am

Chaps

Everything is solved, except for the sub domain issue.

I have added a wildcard subdomain DNS entry

*    A    89.238.179.3

...and I have pinged various random subdomains and they return the correct IP address so I am confident that traffic is getting to my server.

Beyond this, I am not sure that my rewrite rule is not picking up the subdomain. My rules are

Code:

RewriteCond %{HTTP_HOST} ^(www.)?localemergencylocksmiths\.co.uk$ [NC]
RewriteRule ^(.+)/$ http://%{HTTP_HOST}/$1 [R=301,L]

# rewrite for the first and second level pages to index.asp
RewriteEngine on
RewriteBase /
RewriteRule ^[^/]+/[^/]+$ /index.asp [NC,L]

# proxy rule for sub1.domain.com
RewriteCond %{HTTP:Host} ^content\.localemergencylocksmiths\.co.uk$ [NC]
RewriteRule ^[^/]+/[^/]+$ http://www.localemergencylocksmiths.co.uk/index.asp [NC,P,L]


...but http://content.localemergencylocksmiths.co.uk returns a bad request error.

Any pointers?
Kevin


__________________
Regards
Kevin Russell
Fairweather Web LTD
Back to Top Visit FairweatherWeb's Homepage
 
Guests
Guest


Joined: 01 October 2003
Online Status: Online
Posts: -160
Posted: 06 October 2011 at 4:38am

Hi Kevin,

Rule looks okay to me(note that it'd pick up only 2-level URls only, not everyithing).
Would you provide the rewrite.log for the testing request.
Logging issues described in FAQ

Regards
Andrew
Back to Top
 

Page of 2 Next >>
 
Printable version Printable version