views:

41

answers:

1

I wanted to achieve this

example.com/search_results/?action=search&username[equal]=PorscheSA

to

example.com/PorscheSA

I have used .htaccess for many websites to achieve this, but since this website is smarty based, it doesn't seem to work. Any help will be much appreciated.

Ok, this is the .htaccess file:

RewriteCond %{HTTP_HOST} ^www.example.com [NC]
RewriteRule ^(.*)$ http://example.com/$1 [L,R=301]

Options +FollowSymlinks
RewriteEngine on

RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule .* ./index.php

In order to achieve the following I tried this:

RewriteRule ^([a-zA-Z0-9-_+^/])/$ /search_results/?action=search&username[equal]=$1

and nothing happened.

A: 

Your question is still a little vague as to what exactly you expect to have happen, but since you've posted your .htaccess, I'll take a stab at it and see if I get what you were after.

The most obvious reason that your RewriteRule isn't working is that your test pattern doesn't match the URL you've provided as an example, as your RewriteRule requires a trailing slash (and only matches one character before that). Additionally, if you put it after the rules that you currently have in your .htaccess file, it will never match because the request will have already been rewritten to index.php.

I think that you want something like this...

Options +FollowSymlinks

RewriteEngine on

RewriteCond %{HTTP_HOST} =www.example.com [NC]
RewriteRule ^.*$ http://example.com/$0 [L,R=301]

# Make sure we end and force the redirect so %{REQUEST_FILENAME} gets changed
RewriteRule ^[a-zA-Z0-9-_+^/]+$ search_results/?action=search&username[equal]=$0 [L]

RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule .* index.php

However, if the search_results/ directory doesn't exist, then this is just going to be rewritten to index.php anyway, so I'm not sure what the purpose of the redirection would be in that case. And, if it does exist, since your test pattern matches pretty much anything I'd expect to see in a site path, then everything will be rewritten to the search_results/ directory, so very little (if anything) will end up at your site root's index.php.

Based on that, I feel like maybe there's some other criteria that you may have left out, but I could be wrong.

Tim Stone