Page 1 of 1

reg expression for RewriteRule

Posted: Wed Jul 09, 2008 9:31 am
by gurjit
hi

i am trying to write a RewriteRule in a .htaccess file.

i have several links on a page like:

Code: Select all

<a href="../search/?searchtext=Chatham&searchid=Search&type=8630&q=">Chatam</a>

for search engine optimistation I want to write a RewriteRule such that if i pass through the link

Code: Select all

<a href="../8630/estate-agents/chatham/search-results/chatham-estate-agents.html">Chatam</a>
it goes to the .htaccess file and runs the file in the directory ../search/?searchtext=Chatham&searchid=Search&type=8630

in the above href ../8630/estate-agents/chatham/search-results/chatham-estate-agents.html, I am passing through the relevant values to run the query

I do not have the following file/folder on the server ../8630/estate-agents/chatham/search-results/chatham-estate-agents.html

the question is will this work?

I have tried to write the rule myself but eveytime I click the link ../8630/estate-agents/chatham/search-results/chatham-estate-agents.html I get a 404 error, this is because the file/folder does not exist

below is my attempt:

Code: Select all

 
RewriteEngine on
RewriteRule ^/([0-9]+)/([a-zA-Z]+)/([a-zA-Z]+)/([a-zA-Z]+)/(.*?).html$ /search/index.php?searchtext=$3&searchid=Search&type=$1

Re: reg expression for RewriteRule

Posted: Wed Jul 09, 2008 3:59 pm
by Benjamin
Where is the 404 error coming from? Is it coming from the requested page not existing, or is it coming from the page the regex is redirecting to?

Re: reg expression for RewriteRule

Posted: Thu Jul 10, 2008 3:06 am
by gurjit
the 404 comes when i click on the link

Code: Select all

 
<a href="../8630/estate-agents/chatham/search-results/chatham-estate-agents.html">Chatam</a>
 
the folder ="../8630/estate-agents/chatham/search-results/ does not exist and the file chatham-estate-agents.html does not exist. I have placed the .htaccess file in the root folder, so i was hoping if this folder and file does not exist the .htaccess file will match the reg expression

Code: Select all

^/([0-9]+)/([a-zA-Z]+)/([a-zA-Z]+)/([a-zA-Z]+)/(.*?).html$
and redirect to

Code: Select all

/search/index.php?searchtext=$3&searchid=Search&type=$1
 
where $3 is the value chatham, $1 is the value 8630

how can i achieve this.

i will have several links where folders will not exist on the server but the values will be passed through the url link. I want the .htaccess file to read the reg expression - once this matches, redirect it to ]/search/index.php?searchtext=$3&searchid=Search&type=$1, taking the values. this folder ../search/index.php does exist.