?
Solved

How to rewrite url with htaccess to be much simpler?

Posted on 2011-02-11
5
Medium Priority
?
459 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
5 Comments
 
LVL 2

Assisted Solution

by:requeue
requeue earned 1000 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 1000 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

Get real performance insights from real users

Key features:
- Total Pages Views and Load times
- Top Pages Viewed and Load Times
- Real Time Site Page Build Performance
- Users’ Browser and Platform Performance
- Geographic User Breakdown
- And more

Question has a verified solution.

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

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…
Many old projects have bad code, but the budget doesn't exist to rewrite the codebase. You can update this code to be safer by introducing contemporary input validation, sanitation, and safer database queries.
The viewer will learn how to dynamically set the form action using jQuery.
This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.
Suggested Courses

801 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