mod_rewrite and keeping URL arguments

This is a discussion on mod_rewrite and keeping URL arguments within the Apache Web Server forums, part of the Web Server and Related Forums category; I'm trying to create some rewrite rules that will allow me to rewrite the URL to always use a ...


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 08-26-2004
Aidan
 
Posts: n/a
Default mod_rewrite and keeping URL arguments

I'm trying to create some rewrite rules that will allow me to rewrite the
URL to always use a www prefix in the hostname, while at the same time,
preserving any arguments that have been provided wiht the pre-rewritten
URL... this is what I have so far:

RewriteCond %{HTTP_HOST} !^www\.domain\.com [NC]
RewriteCond %{HTTP_HOST} !^$
RewriteRule ^.* http://www.domain.com/$1

If I access my site using just the domain:

http://domain.com

The URL becomes:

http://www.domain.com

But, if I try to access the following:

http://domain.com/index.php?args=123

I just get the URL rewritten as:

http://www.domain.com

Which is not what I want... I want the 'index.php?arg=123' to stay on the
URL and simply have the www prefix added to the host...

I'm not so crash hot with regular expressions, which doesn't help much...
but I'm sure someone here will be able to enlighten me as to what I'm doing
wrong...

Thanks in advance!

Aidan


  #2 (permalink)  
Old 08-26-2004
Davide Bianchi
 
Posts: n/a
Default Re: mod_rewrite and keeping URL arguments

On 2004-08-26, Aidan <nospam.aidan@linknet.com.au> wrote:
> I'm trying to create some rewrite rules that will allow me to rewrite the
> URL to always use a www prefix in the hostname


Use the UseCanonicalName and the ServerName directive for this, no
need to fool around with rewrite.

Davide

--
When you don't know what you are doing, do it neatly.
  #3 (permalink)  
Old 08-26-2004
Aidan
 
Posts: n/a
Default Re: mod_rewrite and keeping URL arguments

Hi Davide,

The problem with that is, that I already am getting some traffic from
google, and I want people who click on links like:

http://domain.com/index.php?args=123

To get the URL in their browser as:

http://www.domain.com/index.php?args=123

I have 4 <VirtualHost> directives: domain.com; domain2.com; www.domain.com;
www.domain2.com; all identical except for the ServerName... Thus to do this,
I think I'm going to need to use mod_rewrite directives in an .htaccess file
at the root of my web-space... I want all these domains to be re-written to
a single domain (www.domain.com), and preserve all the arguments on the URL
they followed... Am I correct in assuming that mod_rewrite is the best tool
for the job in this case? If not, can anyone suggest better way?

Thanks again..

Aidan


"Davide Bianchi" <davideyeahsure@onlyforfun.net> wrote in message
news:slrnciqvvs.1h8.davideyeahsure@fogg.onlyforfun .net...
> On 2004-08-26, Aidan <nospam.aidan@linknet.com.au> wrote:
> > I'm trying to create some rewrite rules that will allow me to rewrite

the
> > URL to always use a www prefix in the hostname

>
> Use the UseCanonicalName and the ServerName directive for this, no
> need to fool around with rewrite.
>
> Davide
>
> --
> When you don't know what you are doing, do it neatly.



  #4 (permalink)  
Old 08-26-2004
Justin Koivisto
 
Posts: n/a
Default Re: mod_rewrite and keeping URL arguments

Aidan wrote:

> I'm trying to create some rewrite rules that will allow me to rewrite the
> URL to always use a www prefix in the hostname, while at the same time,
> preserving any arguments that have been provided wiht the pre-rewritten
> URL... this is what I have so far:
>
> RewriteCond %{HTTP_HOST} !^www\.domain\.com [NC]
> RewriteCond %{HTTP_HOST} !^$
> RewriteRule ^.* http://www.domain.com/$1
>
> If I access my site using just the domain:
>
> http://domain.com
>
> The URL becomes:
>
> http://www.domain.com
>
> But, if I try to access the following:
>
> http://domain.com/index.php?args=123
>
> I just get the URL rewritten as:
>
> http://www.domain.com
>
> Which is not what I want... I want the 'index.php?arg=123' to stay on the
> URL and simply have the www prefix added to the host...
>
> I'm not so crash hot with regular expressions, which doesn't help much...
> but I'm sure someone here will be able to enlighten me as to what I'm doing
> wrong...


RewriteRule ^.* http://www.domain.com/$1 [QSA]

--
Justin Koivisto - spam@koivi.com
http://www.koivi.com
  #5 (permalink)  
Old 08-27-2004
HansH
 
Posts: n/a
Default Re: mod_rewrite and keeping URL arguments

"Aidan" <nospam.aidan@linknet.com.au> schreef in bericht
news:newscache$nqn13i$yv8$1@titan.linknet.com.au.. .
> But, if I try to access the following:
> http://domain.com/index.php?args=123
> I just get the URL rewritten as:
> http://www.domain.com
>
> Which is not what I want... I want the 'index.php?arg=123' to stay on the
> URL and simply have the www prefix added to the host...
>
> I'm not so crash hot with regular expressions, which doesn't help much...
> but I'm sure someone here will be able to enlighten me as to what I'm

doing
> wrong...

Try
RewriteRule ^.* http://www.domain.com/$1 [QSA]

HansH


  #6 (permalink)  
Old 08-27-2004
Aidan
 
Posts: n/a
Default Re: mod_rewrite and keeping URL arguments

Hi Hans,

The [QSA] flag doesn't seem to make a difference for me... the query string
is still removed when I request
"http://domain.com/content/category/2/10/29/" (and rewritten as
"http://www.domain.com/")...

I should probably point out that there are also 2 other rewrite rules in the
..htaccess file.. not sure they would be affecting this though... here's the
full contents of my .htaccess file (the site is running Mambo CMS):

=== .htaccess ===

RewriteEngine On

RewriteBase /

RewriteRule ^content(.*) index.php
RewriteRule ^component/(.*) index.php

RewriteCond %{HTTP_HOST} !^www\.domain\.com [NC]
RewriteCond %{HTTP_HOST} !^$
RewriteRule ^.* http://www.domain.com/$1
[QSA]

=== .htaccess ===

What have I done wrong?!?

Once again, thanks in advance...

Aidan


"HansH" <hans@niet.op.het.net> wrote in message
news:cglqv6$lpn$1@news.cistron.nl...
> "Aidan" <nospam.aidan@linknet.com.au> schreef in bericht
> news:newscache$nqn13i$yv8$1@titan.linknet.com.au.. .
> > But, if I try to access the following:
> > http://domain.com/index.php?args=123
> > I just get the URL rewritten as:
> > http://www.domain.com
> >
> > Which is not what I want... I want the 'index.php?arg=123' to stay on

the
> > URL and simply have the www prefix added to the host...
> >
> > I'm not so crash hot with regular expressions, which doesn't help

much...
> > but I'm sure someone here will be able to enlighten me as to what I'm

> doing
> > wrong...

> Try
> RewriteRule ^.* http://www.domain.com/$1 [QSA]
>
> HansH
>
>



 


Thread Tools
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

vB 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 06:19 AM.


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