How to make htaccess rule for a URL with specific characters? - .htaccess

I need to 301 redirect all ?print=yes URLs to the URLs without ?print=yes that contain the same name in them through .htaccess. Currently the button to PRINT is present in the header of the website so it's more than 70 URLs to fix... Removing the button to PRINT the page will ruin the design quite a bit, so it's not really an option.
I think it needs to be a RedirectMatch rule, but how do I write it?
Example: redirect 301 from domain.com/faq/?print=yes to domain.com/faq
Thanks in advance!

Enable mod_rewrite and .htaccess through httpd.conf and then put this code in your .htaccess under DOCUMENT_ROOT directory:
Options +FollowSymLinks -MultiViews
# Turn mod_rewrite on
RewriteEngine On
RewriteBase /
RewriteCond %{QUERY_STRING} ^print=yes$ [NC]
RewriteRule ^ %{REQUEST_URI}? [R=301,L,NE]

I am not sure if redirect can do the same but here is how I would do it with rewrite
Options +FollowSymlinks
RewriteEngine on
RewriteRule ^(.*)\?print=yes$ $1 [NC]

Related

How can I make it jump to the URL without www when it contains it?

I'm trying to make .htaccess
On this, I would like to state something in order to make visitor jump to the URL without www when it contains it as sub-domain.
How can I write?
For example, when a user goes to the page http://www.test-sample.com/sign_up, I want it to redirect to http://test-sample.com/sign_up
but only when it contains www in sub-domain.
Because there is rare case such as http://forum.test-sample.com/1443
Enable mod_rewrite and .htaccess through httpd.conf and then put this code in your .htaccess under DOCUMENT_ROOT directory:
Options +FollowSymLinks -MultiViews
# Turn mod_rewrite on
RewriteEngine On
RewriteBase /
RewriteCond %{HTTP_HOST} ^www\.(example\.com)$ [NC]
RewriteRule ^ http://%1%{REQUEST_URI} [R=301,L]
This will only redirect www.example.com while leaving www.sub.example.com as it is.

Cannot 301 redirect this page to a specific page

I want this page:
http://mystore.com/Login.aspx?ReturnUrl=%2fPages%2fHome%2fUser%2fWish-list.aspx
to
http://mystore.com/en/ukeurope/home
So, I try to write a 301 redirection rule like this:
RewriteRule ^Login.aspx$ en/ukeurope/home? [R=301,L]
but when I want to try this redirection.
It gives me 404 not Found.
P.S. I don't want another one that is
mystore.com/Page/Login.aspx
to be redirected by this 301 redirection rule
Enable mod_rewrite and .htaccess through httpd.conf and then put this code in your .htaccess under DOCUMENT_ROOT directory:
Options +FollowSymLinks -MultiViews
# Turn mod_rewrite on
RewriteEngine On
RewriteBase /
RewriteCond %{THE_REQUEST} ^[A-Z]{3,}\s/+Login\.aspx?ReturnUrl=\%2fPages\%2fHome\%2fUser\%2fWish-list\.aspx [NC]
RewriteRule ^ /en/ukeurope/home? [R=302,L]

htaccess mod rewrite url with adding up & parameter in url

We have a specific section of games called com_games. Could someone advise on how to rewrite url by adding parameter of & through htaccess so as have 301 redirect
From
http://www.abc.com/?page=4&option=com_games&view=list&Itemid=2
to
http://www.abc.com/?page=4&&option=com_games&view=list&Itemid=2
This needs to be achieve in all pagination pages, How to append & in the url for 301 redirection
Enable mod_rewrite and .htaccess through httpd.conf and then put this code in your .htaccess under DOCUMENT_ROOT directory:
Options +FollowSymLinks -MultiViews
# Turn mod_rewrite on
RewriteEngine On
RewriteBase /
RewriteCond %{THE_REQUEST} ^[A-Z]{3,}\s/\?(page=[^&]+)&([^&][^\s]+)\s [NC]
RewriteRule ^ %{REQUEST_URI}?%1&&%2 [R=301,L]

Pull querystring from cgi-bin with mod_rewrite and redirect

I have a file path that looks like this: /cgi-bin/folder/script.cgi?t=1&u=http://domain.com/url/url-2/
What I want to do is create a rewrite rule to pull the querystring u= and then redirect to that URL, I've been working for a while on this with no success.
RewriteRule ^cgi-bin/folder/script.cgi?t=1&u=(.*)$ $1 [R=301,L]
Above is an example of one of my "solutions" that obviously didn't work. Any help is much appreciated. Thanks!
Enable mod_rewrite and .htaccess through httpd.conf and then put this code in your .htaccess under DOCUMENT_ROOT directory:
Options +FollowSymLinks -MultiViews
# Turn mod_rewrite on
RewriteEngine On
RewriteBase /
RewriteCond %{THE_REQUEST} ^[A-Z]{3,}\s/+cgi-bin/folder/script\.cgi\?t=1&u=([^\s&]+) [NC]
RewriteRule ^ /%1 [R=302,L,NE]

Special characters in mod_rewrite url

I want this URL:
http://www.mydomainblabla.com/s/can+you+drill+shrinky+dinks?.html
to be rewritten to this one:
http://www.mydomainblabla.com/search.php?q=can+you+drill+shrinky+dinks?
I am using this mod_rewrite rule in my .htaccess to accomplish this
RewriteRule ^s/(.+).html$ search.php?q=$1 [L,QSA]
However, the result is not as I want it, when I go to the first url, I get a page not found message.
The same problem occurs when I visit this url:
http://www.mydomainblabla.com/s/http://www.zakgeldnodig.nl/.html
which should be rewritten into this one:
http://www.mydomainblabla.com/search.php?q=http://www.zakgeldnodig.nl/
What modifications should I make to my .htaccess to make this work?
Enable mod_rewrite and .htaccess through httpd.conf and then put this code in your .htaccess under DOCUMENT_ROOT directory:
Options +FollowSymLinks -MultiViews
# Turn mod_rewrite on
RewriteEngine On
RewriteBase /
RewriteCond %{THE_REQUEST} ^[A-Z]{3,}\s/+s/(.+?)\.html [NC]
RewriteRule ^ search.php?q=%1 [L,NE]

Resources