Solved

How to rewrite url with htaccess to be much simpler?

Posted on 2011-02-11
5
442 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
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
Solved
0

Featured Post

Do You Know the 4 Main Threat Actor Types?

Do you know the main threat actor types? Most attackers fall into one of four categories, each with their own favored tactics, techniques, and procedures.

Join & Write a Comment

Part of the Global Positioning System A geocode (https://developers.google.com/maps/documentation/geocoding/) is the major subset of a GPS coordinate (http://en.wikipedia.org/wiki/Global_Positioning_System), the other parts being the altitude and t…
It is possible to boost certain documents at query time in Solr. Query time boosting can be a powerful resource for finding the most relevant and "best" content. Of course the more information you index, the more fields you will be able to use for y…
The viewer will learn how to count occurrences of each item in an array.
The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…

763 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

Need Help in Real-Time?

Connect with top rated Experts

9 Experts available now in Live!

Get 1:1 Help Now