Unwanted query string on Drupal with Permanent Redirect

Oh, the strange things mod_rewrite does!

Unwanted query string on Drupal with Permanent Redirect

Postby axbom » Mon Feb 14, 2005 2:30 am

I'm using the CMS Drupal to power my web site.

Since I've changed my site around and want to accomodate the search engine spiders, I've provided a list of Permanent redirects in my .htaccess. The problem is that Drupal's built-in mod-rewrite takes those new URL:s and adds a query string, thus when I want to redirect /per to /cv
Code: Select all
Redirect permanent /per http://www.axbom.se/cv


the browser ends up at
Code: Select all
http://www.axbom.se/cv?q=per


In this scenario, Drupal is unable to process the URL, and ends up with a 404, although the page
http://www.axbom.se/cv does work with the current mod_rewrite.

How do I make the redirects work and still maintain clean URLs? The current mod_rewrite reads:

Code: Select all
# Various rewrite rules
<IfModule mod_rewrite.c>
  RewriteEngine on

  # Rewrite URLs of the form 'index.php?q=x':
  RewriteCond %{REQUEST_FILENAME} !-f
  RewriteCond %{REQUEST_FILENAME} !-d
  RewriteRule ^(.*)$ index.php?q=$1 [QSA,NE]
</IfModule>
axbom
 
Posts: 3
Joined: Mon Feb 14, 2005 2:14 am

Postby Caterham » Mon Feb 14, 2005 12:49 pm

the external redirect works correct
Code: Select all
http://www.axbom.se/per

GET /per HTTP/1.1
Host: www.axbom.se
[...]

HTTP/1.x 301 Moved Permanently
Date: Mon, 14 Feb 2005 20:42:43 GMT
Server: Apache
Location: http://www.axbom.se/cv
Keep-Alive: timeout=15, max=99
Connection: Keep-Alive
Transfer-Encoding: chunked
Content-Type: text/html; charset=iso-8859-1


To avoid conflicts between both modules, use mod_rewrite for the external redirect, too:
Code: Select all
RewriteEngine on
RewriteRule ^per /cv [R=301,L]

# Rewrite URLs to the form 'index.php?q=x' and append exsisting queryString
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php?q=$1 [QSA,NE]
Caterham
 
Posts: 690
Joined: Fri Dec 10, 2004 1:30 pm

Thanx

Postby axbom » Mon Feb 14, 2005 2:04 pm

Thanx, I figured it out, and that's why it's working ;) When using the RewriteRule it works; it won't work using the Redirect permanent command.
axbom
 
Posts: 3
Joined: Mon Feb 14, 2005 2:14 am


Return to Idiosyncrasies

Who is online

Users browsing this forum: No registered users and 4 guests

cron