2

I have the following code in my .htaccess

RewriteRule ^([a-zA-Z0-9_-]+)/?$ index.php?mode=$1&%{QUERY_STRING})

It works great for one variable but I want to pass some additional variables and would like them to so up like the first one. So instead of having /about/?anotherVar=extra I have /about/extra. The additional variable would be on some pages not all

I now have:

#<IfModule mod_rewrite.c>

#   RewriteEngine on
#    RewriteCond %{REQUEST_FILENAME} !-f
#    RewriteCond %{REQUEST_FILENAME} !-d

#</IfModule>


Options +FollowSymLinks
RewriteEngine on
RewriteRule ^([a-zA-Z0-9_-]+)/?$ index.php?mode=$1 [QSA]
RewriteRule ^([a-zA-Z0-9_-]+)/([a-zA-Z0-9_-]+)/?$ index.php?mode=$1&productContent=$2 [QSA]

1 Answer 1

4
RewriteRule ^([a-zA-Z0-9_-]+)/?$ index.php?mode=$1 [QSA]
RewriteRule ^([a-zA-Z0-9_-]+)/([a-zA-Z0-9_-]+)/?$ index.php?mode=$1&anotherVar=$2 [QSA]

PS the QSA replaces the &%{QUERY_STRING}

Sign up to request clarification or add additional context in comments.

6 Comments

So I would need to replace "anotherVar" with whatever mine will be?
I gave that I try and it doesn't seem to want to work. The following works: /products?productContent=oliveOil but if I try to change it to /products/oliveOil then it won't work.
I should be a little more clear. It works and it loads my page, but I lose parts of my page. I have used <?php include("template.php") ?> on the index page and the mode variable loads the content infomation into the template.php. When I go to add /oliveOil to the URL it loads the right page but does not load the template.php. Is there a solution to this or will I have to stick to using /products?productContent=oliveOil in the URL?
I fixed it!! It wasn't the template.php that was the issue it was all my image and css links that were the problem. Added the domain name in front and all is well. Thanks.
I agree and I usually do, but it was not working when I had the root relative urls. I had to use the domain as well.
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.