Handle mistyping qqq instead of www? %{} variables? Define $1. Define ^.

This is a discussion on Handle mistyping qqq instead of www? %{} variables? Define $1. Define ^. within the Apache Web Server forums, part of the Web Server and Related Forums category; For instance, if someone mistypes www as qqq or eee in the following, http://www.aquaticcreationsnc.com/ I'm told ...


Go Back   Usenet Forums > Web Server and Related Forums > Apache Web Server

FAQ Members List Calendar Search Today's Posts Mark Forums Read
  #1 (permalink)  
Old 05-14-2006
Jim Carlock
 
Posts: n/a
Default Handle mistyping qqq instead of www? %{} variables? Define $1. Define ^.

For instance, if someone mistypes www as qqq or eee in the
following, http://www.aquaticcreationsnc.com/ I'm told I need
to get mod_rewrite to do this inside an .htaccess file. The host
refuses to allow manual editing of the httpd.conf file (they have
some sort of script generator that creates the files).

Microsoft on the other hand provides a separate httpd.conf
for it's FrontPage. Once those files are edited, FrontPage refuses
to connect to the webserver, even if the only edit that occurred
was a blank line (i.e., the FrontPage extensions break). And
it's a FrontPage thing only so I quit messing with it.

FrontPage needs to run for the company owners to access
the website (possibly). They understand FrontPage and it works
for them. So don't fix what's not broke, right?

Anyone here have a link listing all of Apache's %{} variables?

The link I found:
http://httpd.apache.org/docs/1.3/mod...ml#RewriteCond



The following seems to work well enough for what I need it to do.
Is this the only way to handle the job? And does it represent the
best way to handle the task at hand?

RewriteEngine On
# handle the absense of a prefix (we want www)
RewriteCond %{HTTP_HOST} ^aquaticcreationsnc\.com [nc]
RewriteRule ^(.*) http://www.aquaticcreationsnc.com/$1 [R=301,L]
# handle mistyped domain names, qqq.aquaticcreationsnc.com and *.aquaticcreationsnc.com
RewriteCond %{HTTP_HOST} !^www\.aquaticcreationsnc\.com [nc]
RewriteRule ^(.*) http://www.aquaticcreationsnc.com/$1 [R=301,L]

And subdomains get placed inside of DNS rather than letting
Apache handle them. So I don't have to worry about doing any
kind of OR stuff there.

Now, to figure out how that ^ caret symbol should be read. I'm
reading it as, "match anything ending with..." (almost like a preceding
wildcard character), but it has a different meaning in the RewriteRule.
Does that somehow get passed down from the Cond line to the Rule
line? Any help is greatly appreciated.

And anyone able to define $1?

Thank you very much for any and all help.

Jim Carlock
Post replies to the group.
--
Swimming Pool Contractors http://www.aquaticcreationsnc.com/


  #2 (permalink)  
Old 05-14-2006
Robert Ionescu
 
Posts: n/a
Default Re: Handle mistyping qqq instead of www? %{} variables? Define $1.Define ^.

Jim Carlock wrote:
> And does it represent the
> best way to handle the task at hand?


httpd.conf would be always the beset way.
But your first rule is redundant:

RewriteEngine On
# ...not empty
RewriteCond %{HTTP_HOST} !=""
RewriteCond %{HTTP_HOST} !^www\.aquaticcreationsnc\.com [nc]
RewriteRule ^(.*) http://www.aquaticcreationsnc.com/$1 [R=301,L]

> Now, to figure out how that ^ caret symbol should be read. I'm
> reading it as, "match anything ending with..."


That would be $ (abc$ -> ending with abc). It symbols the starting
position of a string.

> Does that somehow get passed down from the Cond line to the Rule
> line?


No, it's a RegEx. But the order of processing is rule-pattern -->
condition(s).

> And anyone able to define $1?


The result captured by evreything between (....), so the part matching
the RegEx .*

--
Robert
  #3 (permalink)  
Old 05-15-2006
Jim Carlock
 
Posts: n/a
Default Re: Handle mistyping qqq instead of www? %{} variables? Define $1. Define ^.

"Robert Ionescu" replied:
> your first rule is redundant:


RewriteEngine On
# ...not empty
RewriteCond %{HTTP_HOST} !=""
RewriteCond %{HTTP_HOST} !^www\.aquaticcreationsnc\.com [nc]
RewriteRule ^(.*) http://www.aquaticcreationsnc.com/$1 [R=301,L]

Thanks for catching that. What's the purpose for the first condition
above? A blank URI can get passed through an .htaccess file?

Jim Carlock
Post replies to the group.
--
Raleigh Swimming Pool Builder http://www.aquaticcreationsnc.com/


 
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are Off
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



All times are GMT +1. The time now is 10:48 PM.


Powered by vBulletin® Version 3.7.3
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO 3.0.0