[Last Call] Learn about multicloud storage options and how to improve your company's cloud strategy. Register Now

x
?
Solved

How to rewrite url with htaccess to be much simpler?

Posted on 2011-02-11
5
Medium Priority
?
460 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

Tech or Treat!

Submit an article about your scariest tech experience—and the solution—and you’ll be automatically entered to win one of 4 fantastic tech gadgets.

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…
Learn how to match and substitute tagged data using PHP regular expressions. Demonstrated on Windows 7, but also applies to other operating systems. Demonstrated technique applies to PHP (all versions) and Firefox, but very similar techniques will w…
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…
Suggested Courses

650 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