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 ...
|
|||||||
| FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read |
|
|||
|
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 |
|
|||
|
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 |
|
|||
|
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. |