Click here to Skip to main content
15,881,794 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi guys,
I got an htaccess question, hopefully you could help me out:

When I have a querystring parameters in URL, I have to make a redirection to the same page without these parameters.

Example:

http://sos-med.com/en/our-offices/endokrinologiya.html?print=1&tmpl=component

must redirect to:

http://sos-med.com/en/our-offices/endokrinologiya.html

What is the code for Htaccess file for:
1. Redirect to the same page while cleaning URL from all parameters
2. Doing this only if parameter "print" exist in URL

Regards,

Vitaly.
Posted
Comments
Sergey Alexandrovich Kryukov 8-Aug-12 18:33pm    
I hope, the file name is ".htaccess", not "htaccess"? Just checking...
--SA

1 solution

Try:

C#
RewriteEngine On
RewriteCond %{QUERY_STRING} ^*print=*$ [NC]
RewriteRule ^(.*)$ %{REQUEST_URI}?


I haven't tried it myself, but that should work. If not, check out the documentation here:

http://httpd.apache.org/docs/current/mod/mod_rewrite.html[^]
 
Share this answer
 
Comments
vit01982 15-Aug-12 17:40pm    
Thank you, but before I try this one, I want to make sure that single url rule is working properly. Please show me htaccess on this example:

http://sos-med.com/en/specific_page.html?print=1&ok=1

must redirect (301) to the same URL with no Query string:

http://sos-med.com/en/specific_page.html

?
TRK3 15-Aug-12 17:47pm    
I'm not here to do your work for you.

I don't have a server set up to try this out on and, as easy as it is to install a stack these days, I am not going to go to all that trouble to test something for you.

Especially, since (assuming you have access to a test server) you could have tested it yourself in about the same amount of time it took you to write the reply. (And if you don't have a test server, then you better set one up before you start making ANY changes on your production server.)

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900