reverse mod_rewrite

This is a discussion on reverse mod_rewrite within the Apache Web Server forums, part of the Web Server and Related Forums category; Hi all, Here's the issue. I have a page with a search form. I use method=get, so when ...


Go Back   Usenet Forums > Web Server and Related Forums > Apache Web Server

FAQ Members List Calendar Search Today's Posts Mark Forums Read
  #1 (permalink)  
Old 12-16-2005
ironcito
 
Posts: n/a
Default reverse mod_rewrite

Hi all,

Here's the issue. I have a page with a search form. I use method=get,
so when the user searches for "string", the form gets
example.com/script.php?query=string
I want the URI to become example.com/search/string (which would then be
re-rewritten to have a script actually perform the search)
I tried writing a rule for it, but URI-passed variables seem to mess it
up. I can get it to rewrite script.php to /search, but I can't
transform the variables. How can I do this? Thanks in advance.

Diego

  #2 (permalink)  
Old 12-16-2005
ironcito
 
Posts: n/a
Default Re: reverse mod_rewrite

Davide Bianchi wrote:

> If you search some messages before, there was quite a discussions about
> the pro and cons of doing it.


You mean the pros and cons of having a simple URI for displaying search
results? What could be the cons of having /search=string instead of
/search.php?query=string ? Do you have a link to a discussion on the
subject? I can't think of any disadvantage to that approach.
Thanks for your help :-)

Diego

  #3 (permalink)  
Old 12-17-2005
google@yourimedia.com
 
Posts: n/a
Default Re: reverse mod_rewrite

I was able to do this by learning from WordPress' mod_rewrite(s) and
use variants of:

RewriteEngine On
RewriteCond %{REQUEST_FILENAME} -f [OR]
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^.*$ - [S=39]
RewriteRule ^(.+[^\.])/?$ /index.php?page=$1 [QSA,L]

"index.php" is the hidden script that does the work behind the scenes.

another version:

RewriteCond %{REQUEST_FILENAME} -f
RewriteRule ^.*$ - [S=39]
RewriteRule ^([\w]+\-.*\.php)$ display.php?page=$1 [QSA,L]

"display.php" is the hidden script working behind the scenes.

The trick is to get the REGEX inside the parenthesis to match what you
are looking for. You'll probably have better luck with the first, as
the second looks for "file names" containing dashes.

Then, inside PHP, use functions to break apart and identify the query.

 
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are Off
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On




All times are GMT +1. The time now is 02:21 AM.


Powered by vBulletin® Version 3.7.3
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO 3.0.0