hide a folder in a url with parameters in php using htaccess

Hi I want to hide a folder name in a url using htaccess using RewriteRule but cannot seem to get it to work

rename this: https://mysite.com/index.php?route=product/details&productno=1&qty=1&color_id=1&size_id=0&options=
to https://mysite.com/index.php?route=productoptions&productno=1&qty=1&color_id=1&size_id=0&options=
or this output:
https://mysite.com/productoptions&productno=1&qty=1&color_id=1&size_id=0&options=

this is what I have tried
RewriteRule ^index.php?route=productoptions$ /index.php?route=product/details$1 [QSA]
LVL 3
taz8020Asked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Steve BinkCommented:
The query string must be handled through a RewriteCond directive.  Something like this:
RewriteCond %{QUERY_STRING} ^(.*&)?route=productoptions(&.*)?$ [NC]
RewriteRule /?index.php /index.php?%1route=product/details%2 [NC]

Open in new window


See this tips page for more strategies.  You might want to consider other options, such as re-routing at the application level.
0
taz8020Author Commented:
Hi Thanks for that but get page not found, any other ideas?
0
Steve BinkCommented:
You'll need to turn on your rewrite log and post some detail before I can help you further.

Either that, or try one of the suggestions found at the link I posted.
0
Upgrade your Question Security!

Your question, your audience. Choose who sees your identity—and your question—with question security.

Vimal DMSenior Software EngineerCommented:
HI,

A sample HTACCESS script of change the url inorder to hide the folder path...

Options +FollowSymLinks -Multiviews
RewriteEngine On

RewriteCond %{HTTP_HOST} ^sub\.example\.com$ [NC]
RewriteCond %{THE_REQUEST} \ /folder/\?qvar=([^&\ ]+)
RewriteRule ^ /folder/%1? [L,R=301]

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{HTTP_HOST} ^sub\.example\.com$ [NC]
RewriteRule ^folder/(.*)$ /folder/?qvar=$1 [L,QSA]
0
taz8020Author Commented:
I got the below to work but cannot get the first way i mentioned to work:

RewriteRule ^productoptions/([^/]*)/([^/]*)/([^/]*)/([^/]*)/([^/]*)$ /index.php?route=product/details&productno=$1&qty=$2&color_id=$3&size_id=$4&options=$5 [L]
0
Steve BinkCommented:
What are the other parts of the URL you are detecting in that rule?

Back to square 1...  we need to see:

a) What URL is being requested by the client
b) What that same URL needs to look like when it hits your application
0
taz8020Author Commented:
this is what I want the user to see
https://mysite.com/index.php?route=productoptions&productno=1&qty=1&color_id=1&size_id=0&options=

but need to go here
https://mysite.com/index.php?route=product/details&productno=1&qty=1&color_id=1&size_id=0&options=

Please note its on https if that makes a difference?
0
Steve BinkCommented:
What about the rest of the pathing you referenced in your previous post?
0
taz8020Author Commented:
In the other post I was just trying things out and with the below rule

RewriteRule ^productoptions/([^/]*)/([^/]*)/([^/]*)/([^/]*)/([^/]*)$ /index.php?route=product/details&productno=$1&qty=$2&color_id=$3&size_id=$4&options=$5 [L]

this url works

https://mysite.com/1/2/3/4/5

but cannot get the other one working, I just thought this might help get the other one going. I did manage to get the log going but does not give much info just looks like its forwarding to index.php

I do know that if not all 5 parameters are supplied it will return page not found.
0
Steve BinkCommented:
Make sure your rewrite log is turned on, and clear the log.  Use this set of rules:
RewriteCond %{QUERY_STRING} ^(.*&)?route=productoptions(&.*)?$ [NC]
RewriteRule /?index.php /index.php?%1route=product/details%2 [NC]

Open in new window

Then try to browse to a single URL that should trigger that rule.  Post the results and the log entries here.
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
taz8020Author Commented:
Ok I cleared the logs then restared  apache went to the url
https://mysite.com/index.php?route=productoptions&productno=1&qty=1&color_id=1&size_id=0&options=

but after having a look in the logs its not picking up the rewriteCond, I did a search on "productoptions" with your code cannot see it.

I then tried using the other bit of code that works (but not the way I want) and can see it in the logs.
so I take it its something in the condition??

just to confirm it is a module that is creating the url and is the module name I am trying to rewrite.
0
taz8020Author Commented:
Wow I cannot believe how long this has taken but is now going, but Steve you were the closest.

in the end this is what worked, but thanks for your help in getting there.

RewriteCond %{QUERY_STRING} ^route=(productoptions)(.*)$
RewriteRule ^(.*)$ $1?route=product/details%2 [L]
0
taz8020Author Commented:
Very close
0
Steve BinkCommented:
Note that the lack of a beginning wildcard on the conditions means that "route" *must* be the first parameter in the query string for this rule to work.  Any URL violating that constraint will not trigger the rewrite.  My first rule suggestion accounts for this with the initial wildcard.
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
PHP

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.