views:

89

answers:

2

I'm trying to make seo to search queries. i've got a form like this:

 <form action="index.php?<?=$_GET['search-input01']?>'" method="get">
   <p class="nom t-center">
     <label for="search-input01">All:</label>
     <input type="text" size="75" name="q" id="search-input01" />
     <input type="image" src="design/search-button.gif" class="search-submit" />
   </p>
 </form>

when u do search /index.php?q=SEARCHTERMHERE&x=0&y=0 in adress bar. I want to make this: /search-SEARCHTERMHERE

how to do?

+3  A: 

Try something like this:

if (isset($_GET['q'])) {
    header('Location: http://example.com/search-'.rawurlencode($_GET['q']));
    exit;
}

This will redirect a request that’s URL query contains a q argument like in your /index.php?q=SEARCHTERMHERE&x=0&y=0 to /search-SEARCHTERMHERE.


Edit    You can also try this with mod_rewrite only:

RewriteCond %{THE_REQUEST} ^GET\ /index\.php\?
RewriteCond %{QUERY_STRING} ^(([^&]*&+)*)q=([^&]*)&*(.*)
RewriteRule ^index\.php$ /search-%3?%1%4 [L,R]

RewriteRule ^search-(.+) index.php?q=$1 [L,QSA]

The first rule is to redirect the request externally and the second is for the internal rewrite.

Gumbo
Ronnie Chester Lynwood
Ronnie Chester Lynwood
+2  A: 

If you want to do the opposite of what Gumbo suggested, i.e. redirect /search-SEARCHTERM to /index.php?q=SEARCHTERM&x=0&y=0, enter something like this in your .htaccess file:

RewriteEngine On
RewriteRule ^search-([-_A-Za-z0-9]+)$ /index.php?q=$1&x=0&y=0 [L]
Tomba
Ronnie Chester Lynwood
can you give an example of a typical search term?
Tomba
Ronnie Chester Lynwood
IF the index.php is not in your server root, remove the / before index.php. Have you tried adding <?php var_dump($_GET); ?> to your index.php to see what paramters are passed?
Tomba
dump: array(0) { } removing / not workd. do u have msnmsgr?
Ronnie Chester Lynwood