Web Hosting Talk







View Full Version : Need some mod_rewrite help


Arber
02-27-2010, 12:28 PM
So I am working on a little script & I am doing some mod_rewrite and I need some help

RewriteCond %{REQUEST_URI} /index.php$
RewriteCond %{QUERY_STRING} ^search=([A-Za-z0-9\+]+)$
RewriteRule ^(.*)$ /search/1/%1\.html [R=301,L]

RewriteRule ^search/([^/]*)/([^/]*)\.html$ /index.php?page=$1&search=$2 [L]

I have that but when I search it does
http://www.MYDOMAIN.com/search/1/MYSEARCH.html?search=MYSEARCH

how do I remove the ?search=MYSEARCH

angathan
02-27-2010, 11:14 PM
Hi,

Just try changing the rewrite rule
RewriteRule ^(.*)$ /search/1/%1\.html [R=301,L]

Specify the file or location istead of ^(.*)$

mattle
03-01-2010, 09:00 AM
So I am working on a little script & I am doing some mod_rewrite and I need some help

RewriteCond %{REQUEST_URI} /index.php$

This seems troublesome to me...

1. Do you really want to match everything that ends with '/index.php' (that would include '/index.php', '/foo/index.php', '/bar/index.php'...)

2. If I'm not mistaken the URI will also include the query string, so this condition only matches if there is not one and the next condition only matches if there is one! Maybe I'm wrong about this, if you are getting matches, however.

RewriteCond %{QUERY_STRING} ^search=([A-Za-z0-9\+]+)$
RewriteRule ^(.*)$ /search/1/%1\.html [R=301,L]

RewriteRule ^search/([^/]*)/([^/]*)\.html$ /index.php?page=$1&search=$2 [L]

I have that but when I search it does
http://www.MYDOMAIN.com/search/1/MYSEARCH.html?search=MYSEARCH

how do I remove the ?search=MYSEARCH

Either way, I agree with angathon, instead of using rewrite conditions to look at parts of the URI, just use a specific regex in your rewrite rule:


RewriteRule ^index.php?search=([A-Za-z0-9\+]+)$ /search/1/$1.html [R=301,L]

HivelocityDD
03-03-2010, 01:30 PM
RewriteRule ^search/(.*)/(.*)\.html$ /index.php?page=$1


Is this you are looking for ?