You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@httpd.apache.org by Philip Pemberton <us...@philpem.me.uk> on 2006/09/18 10:57:32 UTC
[users@httpd] Extra garbage in URL when using mod_rewrite with redirects
Hi,
I have the following rewrite rules in my site's .htaccess:
--- begin cut
RewriteEngine On
# Only rewrite URLs on the primary domain, not subdomains
RewriteCond %{HTTP_HOST} ^www\.philpem\.me\.uk$ [OR]
RewriteCond %{HTTP_HOST} ^philpem\.me\.uk$
# This makes sure AWStats can get through
RewriteCond %{REQUEST_URI} !^/awstats.* [NC]
# page manager
RewriteCond %{DOCUMENT_ROOT}%{REQUEST_URI} !-f
RewriteRule ^(.*)$ index.php?$1 [L]
-- end cut
The problem is, a few other sites are linking to my site using old URLs
(www.philpem.me.uk/forum, for example is now forum.philpem.me.uk). To get
around this, I've added this rule to my htaccess:
RedirectPermanent /forum http://forum.philpem.me.uk
RedirectPermanent /blog http://blog.philpem.me.uk
My problem is that when the redirect is triggered by someone going to
http://www.philpem.me.uk/forum/, instead of being redirected to
http://forum.philpem.me.uk/, they're redirected to
http://forum.philpem.me.uk//?forum/. Similarly, /blog redirects to
http://blog.philpem.me.uk/?blog/.
Although the stuff after the ? is pretty benign (the scripts in those
directories just ignore it), for the sake of URL tidiness I'd like to get rid
of it. Can anyone tell me what I need to add to my htaccess to do that?
Thanks.
--
Phil. | (\_/) This is Bunny. Copy and paste Bunny
usenet06@philpem.me.uk | (='.'=) into your signature to help him gain
http://www.philpem.me.uk/ | (")_(") world domination.
If mail bounces, replace "06" with the last two digits of the current year.
---------------------------------------------------------------------
The official User-To-User support forum of the Apache HTTP Server Project.
See <URL:http://httpd.apache.org/userslist.html> for more info.
To unsubscribe, e-mail: users-unsubscribe@httpd.apache.org
" from the digest: users-digest-unsubscribe@httpd.apache.org
For additional commands, e-mail: users-help@httpd.apache.org
[users@httpd] Re: Extra garbage in URL when using mod_rewrite with redirects
Posted by Philip Pemberton <us...@philpem.me.uk>.
Joshua Slive wrote:
> Don't mix mod_rewrite and mod_alias. In place of those
> RedirectPermanent, use
> RewriteRule ^forum http://forum.philpem.me.uk [R=permanent,L]
> etc...
That sorted it - thanks.
Now the only problem is I have a pair of RewriteCond commands for each
redirect, and all of them need to be kept up to date.. Other than that, it's
working great.
Thanks.
--
Phil. | (\_/) This is Bunny. Copy and paste Bunny
usenet06@philpem.me.uk | (='.'=) into your signature to help him gain
http://www.philpem.me.uk/ | (")_(") world domination.
If mail bounces, replace "06" with the last two digits of the current year.
---------------------------------------------------------------------
The official User-To-User support forum of the Apache HTTP Server Project.
See <URL:http://httpd.apache.org/userslist.html> for more info.
To unsubscribe, e-mail: users-unsubscribe@httpd.apache.org
" from the digest: users-digest-unsubscribe@httpd.apache.org
For additional commands, e-mail: users-help@httpd.apache.org
Re: [users@httpd] Extra garbage in URL when using mod_rewrite with redirects
Posted by Joshua Slive <jo...@slive.ca>.
On 9/18/06, Philip Pemberton <us...@philpem.me.uk> wrote:
> RedirectPermanent /forum http://forum.philpem.me.uk
> RedirectPermanent /blog http://blog.philpem.me.uk
>
> Although the stuff after the ? is pretty benign (the scripts in those
> directories just ignore it), for the sake of URL tidiness I'd like to get rid
> of it. Can anyone tell me what I need to add to my htaccess to do that?
Don't mix mod_rewrite and mod_alias. In place of those RedirectPermanent, use
RewriteRule ^forum http://forum.philpem.me.uk [R=permanent,L]
etc...
(That might be exactly what you need, but it should be close.)
Joshua.
---------------------------------------------------------------------
The official User-To-User support forum of the Apache HTTP Server Project.
See <URL:http://httpd.apache.org/userslist.html> for more info.
To unsubscribe, e-mail: users-unsubscribe@httpd.apache.org
" from the digest: users-digest-unsubscribe@httpd.apache.org
For additional commands, e-mail: users-help@httpd.apache.org