Adding a redirect

New to mod_rewrite? This is a good place to start.

Adding a redirect

Postby ajkochanowicz » Thu Sep 17, 2009 1:35 pm

Currently, anything after "Vegan.fm/" redirects to a search query for the wiki at "vegan.fm/isitvegan"
So "vegan.fm/casein" returns a search page for "casein"

This works okay, however, I'd like to add a simple redirect for "vegan.fm/places" to go to the places entry (/isitvegan/doku.php?id=places) instead of the query (/isitvegan/doku.php?do=search&id=places)

This is what I have, can you tell me what's wrong?
---------------------

Options +FollowSymLinks

RewriteEngine On

# Trying to take "vegan.fm/places" directly to the places page instead of query.
RewriteRule ^/places$ /isitvegan/doku.php?id=places

# Everything I have after this point works fine. I only added the top rewrite rule
# If it's not a request to an existing file
RewriteCond %{SCRIPT_FILENAME} !-f
# and it's not a request to an existing directory
RewriteCond %{SCRIPT_FILENAME} !-d
# send the request to /isitvegan/doku.php?do=search&id=
RewriteRule ^(.+)$ /isitvegan/doku.php?do=search&id=$1 [QSA,L]
ajkochanowicz
 
Posts: 4
Joined: Wed Jul 22, 2009 9:32 pm

Postby richardk » Thu Sep 17, 2009 3:53 pm

In .htaccess files (and <Directory>s) the part of the URL the RewriteRule matches against is relative to the directory the .htaccess file is in. This means that the pattern should not start ^/ in your document root.

Try
Code: Select all
Options +FollowSymLinks

RewriteEngine On

RewriteRule ^places$ /isitvegan/doku.php?id=places [QSA,L]

RewriteCond %{SCRIPT_FILENAME} !-f
RewriteCond %{SCRIPT_FILENAME} !-d
RewriteRule ^(.+)$ /isitvegan/doku.php?do=search&id=$1 [QSA,L]
richardk
 
Posts: 8800
Joined: Wed Dec 21, 2005 7:50 am

Thanks!

Postby ajkochanowicz » Fri Oct 02, 2009 12:34 pm

This worked PERFECTLY, thank you!!
ajkochanowicz
 
Posts: 4
Joined: Wed Jul 22, 2009 9:32 pm


Return to Beginner's Corner

Who is online

Users browsing this forum: Google [Bot] and 25 guests

cron