Solved

How to rewrite url with htaccess to be much simpler?

Posted on 2011-02-11
5
450 Views
Last Modified: 2013-12-13
I have a webshop where there is a search field. When I search I am forwarded to a link looking like this:

webshopdomain.com/index.php?route=product/search&keyword=my search phrase

(webshopdomain.com/index.php?route=product/search&keyword=my%20search%20phrase )

What do I need to put in htaccess to do the same search by writing : webshopdomain.com/search/my%20search%20phrase
(and keep that url after)

I have been playing around with this tool ( http://www.webconfs.com/url-rewriting-tool.php ) , but haven't understood how to just grab the search phrase and put that into a static url.

I have also been googling, but in lack of the correct wording, I haven't found the answer.

The issue seams to be just retracting the search phrase and nothing else, and put that into a new url...
0
Comment
Question by:Respons
  • 3
5 Comments
 
LVL 2

Assisted Solution

by:requeue
requeue earned 250 total points
ID: 34870497
Hi,

htaccess will be like follows:

RewriteEngine on
RewriteRule index.php\?route=product/search&keyword=(.*) search/$1

Open in new window


The rule is:
RewriteRule Pattern Substitution [flags]

Please see detail here:
http://httpd.apache.org/docs/current/en/mod/mod_rewrite.html#rewriterule
0
 

Author Comment

by:Respons
ID: 34870592
Him and thanks.

I thought so too, but I can not get it to work.

I forgot to mention that there exist a htaccess from before. Looks lie this:


Options +FollowSymlinks
Options -Indexes
<FilesMatch "\.(tpl|ini)">
 Order deny,allow
 Deny from all
</FilesMatch>
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)\?*$ index.php?_route_=$1 [L,QSA]

Open in new window


0
 
LVL 6

Accepted Solution

by:
de2Zotjes earned 250 total points
ID: 34870918
You want the user to be able to type:
http://webshopdomain.com/search/my_search_phrase in the addressbar and get a search result back?

If that is the case the rewiterule proposed by requeue is backwards, to convert from search/... to a url that will do the actual searching:

RewriteRule ^search/(.*)$  index.php\?route=product/search&keyword=$1

0
 

Author Comment

by:Respons
ID: 34870984
Hi, and thanks again.

It didn't work.

But after testing a lot I found that if I put the
RewriteRule ^search/(.*)$  index.php\?route=product/search&keyword=$1

BEFORE


RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)\?*$ index.php?_route_=$1 [L,QSA]


it works ;-)

Thanks!
0
 

Author Closing Comment

by:Respons
ID: 34871259
Solved
0

Featured Post

PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

If you've heard about htaccess and it sounds like it does what you want, but you're not sure how it works... well, you're in the right place. Read on. Some Basics #1. It's a file and its filename is .htaccess (yes, with a dot in the front). #…
Password hashing is better than message digests or encryption, and you should be using it instead of message digests or encryption.  Find out why and how in this article, which supplements the original article on PHP Client Registration, Login, Logo…
The viewer will learn how to dynamically set the form action using jQuery.
The viewer will learn how to count occurrences of each item in an array.

810 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question