removing just "?m=1" from url using rewrite rule - wordpress

just few day before i had migrated my blogger blog to wordpress. Now i find crawn error with many url, at the end of many url the name and value is there (?m=1) which shown as a 404 error now i want to redirect all the url additing .htaccess file
example:
http://www.tipsviablogging.com/blogger-tricks/facebook-disqus-tab-in-blogger.html?m=1
musy redirect to
http://www.tipsviablogging.com/blogger-tricks/facebook-disqus-tab-in-blogger.html
any one is having expertise in url rewrite kindly help me...

I haven't got a test system handy, but something like this in your .htaccess should do the trick:
RewriteEngine On
RewriteCond %{QUERY_STRING} ^m=1$
RewriteRule ^(.*)$ /$1? [R=301,L]
If memory serves, you need the ? at the end of the target in the RewriteRule to stop the original query string being appended.
The code assumes you haven't got any other parameters (eg it won't work if you have ?m=1&foo=bar).

I want to add a solution on NginX:
Use below code in "location /" Of VirtualHost config
if ($query_string ~ "^m=1$"){
rewrite ^(.*)$ /$1? redirect;
}

Related

How to redirect http to specific URL using htaccess in WordPress

I am looking for assistance with the redirection rules.
I have url www.example.com.au and I want the following redirections
https://www.example.com.au =>https://www.example.com.au
http://www.example.com.au =>https://www.example.com.au/page-2
I found the following .htaccess rules but its not working for me
RewriteEngine On
RewriteCond %{HTTP_HOST} www^example\.com.au [NC]
RewriteCond %{HTTPS} off
RewriteRule ^(.*)$ https://%.
{HTTP_HOST}%www^example.com.au/page-2 [302 L]
can anyone please help me the correct rule.
I will be using the above rule for a WordPress site so do i need to paste the above rules at the bottom so that it doesn't overruled by other rewrite rule?
Thanks in advance.
For the first redirection it is impossible, it will create an infinite loop. You can not redirect an url on itself.
And for the second one ( http://www.example.com.au => https://www.example.com.au/page-2 ) you can do something like that
Redirect 301 / https://www.example.com.au/page-2
Pay attention to 301, it indicates that the redirection is permanent, I do not know if it is your goal.
But if your goals was to redirect http to https you can do something like that (put on the top of your .htaccess file):
RewriteEngine on
RewriteCond %{HTTP:X-Forwarded-Proto} !https
RewriteRule (.*) https://www.example.com.au/$1 [R=301,L]
Or use a plugin like Really Simple SSL
Then you can define your rules to redirect one page to another before the rule above, like this:
Redirect 301 /old-page /new-page

htaccess redirect with exceptions

I work on a Wordpress Network. Let's say that the main site has the link www.main-site-old.com, and all the other sites in this network have links like www.main-site-old.com/site1 , www.main-site-old.com/site2 e.t.c.
I want to redirect ONLY the main site to a new domain (let's say www.main-site-new.com) and let all the others stay as they are.
I tried this one:
Redirect 301 / http://www.main-site-new.com/
but it redirects the whole domain (for example it redirects www.main-site-old.com/site1 to www.main-site-new.com/site1)
I also tried:
RewriteCond %{REQUEST_URI} !=/site1
RewriteRule ^.*$ http://main-site-new.com/$0 [R=301,L]
but nothing happened.
With mod_alias redirect you will not be able to use regex to capture a request for http://www.main-site-old.com only so, you could use another one RedirectMatch like this :
RedirectMatch 301 ^/?$ http://www.main-site-new.com
Or go to mod_rewrite by this :
RewriteEngine On
RewriteRule ^/?$ http://www.main-site-new.com [R=301,L]
Note: clear browser cache then test.

Trying to redirect an url based on a pattern but failed

I am trying to redirect an url like this http://domain.com/2011/09/rugs-from-therese-sennerholt/comment-page-1/ to the index page http://domain.com/.
I tried
RewriteRule ^(.*)/comment-page-(.*)/ $1/ [L,R=301,L]
But not working it is still pointing to a 404 page.
You need to use this rule as your very first rule just below RewriteEngine On line:
RewriteRule ^(.+?)/comment-page- /? [L,R=301]

NGINX URL Masking

We have a server where nginx is installed, we have also configured PHP As FastCGI on the server. Everything is working fine except rewrite rule. Our requirement is to mask an URL
for eg:- if someone search in our website the URL which comes will be like http://example.com/search.php?searchword=$1 ($1=searched word) . We need to display URL for our customers as http://example.com/$1.html.
We have set rewrite rule as rewrite ^/(([a-zA-Z_0-9]|-)+/?)$ /search.php?searchword=$1 break;
The URL is getting redirected however we get a file not found error each time. How can we mask the URL just as we do in Apache. Any help would be greatly appreciated
Equivalent Apache htaccess rules which we used are as follows
RewriteCond %{REQUEST_URI} !index\.html$ [NC]
RewriteRule ^([a-zA-Z0-9-/]+).html$ search.php?searchword=$1 [L]
RewriteRule ^([a-zA-Z0-9-/]+).html/$ search.php?searchword=$1 [L]
It was working fine with Apache
You should put this rewrite code to location / . I've tested it on my server.
location / {
rewrite ^/([a-zA-Z0-9/-]+).html/?$ /search.php?searchword=$1 last;
}

Using .htaccess to redirect a domain to another URL

I have a site running wordpress, it's the full site. One of the pages is like a contact-us form located at www.ourdomain.com/contact-us/
I also have a URL like contactourdomain.com and I want it to redirect to www.ourdomain.com/contact-us/
We used to do this with a redirect on network solutions, but I prefer to have it all done right on the server if possible. I've got it sort of working but when you visit the link is still says contactourdomain.com/contact-us/ as the URL, and that breaks all the other ones.
Any suggestions?
.htaccess
Options -MultiViews
RewriteEngine on
RewriteBase /
# Rewrite
RewriteRule ^(.*)$ http://www.ourdomain.com/contact-us//$1 [L]
if you add this in .htaccess is it working?:
RewriteRule ^$ contact-us/ [R=301,L]
keep me posted..

Resources