Solved

How to rewrite url with htaccess to be much simpler?

Posted on 2011-02-11
5
457 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 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

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

If you are a web developer, you would be aware of the <iframe> tag in HTML. The <iframe> stands for inline frame and is used to embed another document within the current HTML document. The embedded document could be even another website.
This article discusses how to create an extensible mechanism for linked drop downs.
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
The viewer will learn how to count occurrences of each item in an array.

737 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