Newbie Question

Using a single web hosting account to host multiple sites

Postby weewah » Wed Jun 24, 2009 7:12 pm

For the first requirement, do I need to use passthrough as well if they page can reside in the appserver?, i.e. [QSA,PT,L]

Code: Select all
RewriteEngine On

# Make sure it's not (!) a request to www.exmaple.com.
RewriteCond %{HTTP_HOST} !^www\.example\.com$ [NC]
# If it is a sub domain request (either www.sub.example.com or sub.example.com)
RewriteCond %{HTTP_HOST} ^(www\.)?([a-z]+)\.example\.com$ [NC]
# and it is a request for / (the site's root) rewrite the request to /xxx/yyy?page=sub.
RewriteRule ^/$ /xxx/yyy?page=%2 [QSA,L]


Thanks.
weewah
 
Posts: 20
Joined: Fri Jun 12, 2009 6:37 am

Postby weewah » Wed Jun 24, 2009 7:16 pm

What does this piece of code do? You did not explain earlier. Is it necessary for requirement 1?

Code: Select all
RewriteCond %{ENV:REDIRECT_STATUS} ^$


Thanks.
weewah
 
Posts: 20
Joined: Fri Jun 12, 2009 6:37 am

Postby weewah » Thu Jun 25, 2009 1:27 am

For the below code, is it necessary to have QSA, since "?" is not even in the URL for the rewrite rule? In fact, I don't need to retain the query string, i.e. http://www.abc.com/pattern should redirect to http://www.abc.com/def/feg?type=pattern, but http://www.abc.com/pattern?string should fail. There's no difference when I used [QSA,PT,L] versus [PT,L]. Both still get processed and directed to http://www.abc.com/def/feg?type=pattern.

Code: Select all
RewriteEngine on
# If it's not a request to an existing file
RewriteCond %{DOCUMENT_ROOT}%{SCRIPT_FILENAME} !-f
# and if it's not a request to an existing directory
RewriteCond %{DOCUMENT_ROOT}%{SCRIPT_FILENAME} !-d
# and it matches "pattern1" rewrite to /abc/def?type=pattern1.
RewriteRule ^/([\w\s\-&\(\)\.]+)$ /abc/def?type=$1 [QSA,PT,L]


Thanks.
weewah
 
Posts: 20
Joined: Fri Jun 12, 2009 6:37 am

Postby richardk » Thu Jun 25, 2009 1:06 pm

What does this piece of code do? You did not explain earlier. Is it necessary for requirement 1?
Code: Select all
RewriteCond %{ENV:REDIRECT_STATUS} ^$

It is only required in .htaccess files and <Directory>s. This is because the mod_rewrite in them is processed at a later stage in the request processing and a new sub request is made for the file you want. If the rule matches the new request as well it will loop.

In a <VirtualHost>, a request to /pattern is matched, turned into /abc/def?type=pattern, and /abc/def is shown.

In a .htaccess file the request for /pattern is matched, turned into /abc/def?type=pattern, a new sub request is made for /abc/def?type=pattern, mod_rewrite is processed again and (if no rule matches) /abc/def is shown.

The sub request has to be made because checks like authentication have already been done by the time a .htaccess file is processed and could be different for the new sub request.

but http://www.abc.com/pattern?string should fail. There's no difference when I used [QSA,PT,L] versus [PT,L]. Both still get processed and directed to http://www.abc.com/def/feg?type=pattern.

If you want to only match empty query strings, add
Code: Select all
RewriteCond %{QUERY_STRING} ^$
richardk
 
Posts: 8800
Joined: Wed Dec 21, 2005 7:50 am

Postby weewah » Thu Jun 25, 2009 5:59 pm

Can QSA be omitted then? It is of no use?
weewah
 
Posts: 20
Joined: Fri Jun 12, 2009 6:37 am

Postby weewah » Thu Jun 25, 2009 6:11 pm

I tried the below. It doesn't work.

RewriteCond %{QUERY_STRING} ^$
weewah
 
Posts: 20
Joined: Fri Jun 12, 2009 6:37 am

Postby richardk » Fri Jun 26, 2009 9:06 am

Can QSA be omitted then? It is of no use?

Yes.

I tried the below. It doesn't work.
Code: Select all
RewriteCond %{QUERY_STRING} ^$

Your going to need to provide a little bit more information than that.

Where did you put it? (Post your current mod_rewrite.)
What URL did you access?
What happened?
What was supposed to happen?
richardk
 
Posts: 8800
Joined: Wed Dec 21, 2005 7:50 am

Postby weewah » Sat Jun 27, 2009 5:18 am

Sorry I was not clear.

My code is as follows:
Code: Select all
RewriteEngine on
# If it's not a request to an existing file
RewriteCond %{DOCUMENT_ROOT}%{SCRIPT_FILENAME} !-f
# and if it's not a request to an existing directory
RewriteCond %{DOCUMENT_ROOT}%{SCRIPT_FILENAME} !-d
RewriteCond %{QUERY_STRING} ^$
# and it matches "pattern1" rewrite to /abc/def?type=pattern1.
RewriteRule ^/([\w\s\-&\(\)\.]+)$ /abc/def?type=$1 [QSA,PT,L]


I'm trying to access http://www.example.com/pattern1?abc. I'm expecting this to fail and it does, however, http://www.example.com/pattern1 failed as well when I expect it to be rewritten to /abc/def?type=pattern1.
weewah
 
Posts: 20
Joined: Fri Jun 12, 2009 6:37 am

Postby richardk » Sun Jun 28, 2009 12:31 pm

And when you remove the %{QUERY_STRING} condition both work?

Try
Code: Select all
RewriteEngine On

RewriteCond %{THE_REQUEST} !\?
RewriteCond %{DOCUMENT_ROOT}%{SCRIPT_FILENAME} !-f
RewriteCond %{DOCUMENT_ROOT}%{SCRIPT_FILENAME} !-d
RewriteRule ^/([\w\s\-&\(\)\.]+)$ /abc/def?type=$1 [QSA,PT,L]
richardk
 
Posts: 8800
Joined: Wed Dec 21, 2005 7:50 am

Postby weewah » Sun Jun 28, 2009 11:21 pm

And when you remove the %{QUERY_STRING} condition both work?

Yes, that's correct.

What does the below mean? The request does not contain "?" ?
Code: Select all
RewriteCond %{THE_REQUEST} !\?
weewah
 
Posts: 20
Joined: Fri Jun 12, 2009 6:37 am

PreviousNext

Return to Domain Handling

Who is online

Users browsing this forum: Yahoo [Bot] and 1 guest

cron