Suddenly GWT has reported over 50 404 errors for urls of this type
http://example.com/abc/&sa=U&ved=0CCYQFjADahUKEwi_lo-6nInHAhXIoZQKHfkXDZw&usg=AFQjCNEfkaKtU35GolQ-KLlTBjIuoMejlQ
I want to redirect these ugly and irrelevant urls to the actual URL i.e http://example.com/abc/
Will this code do the job
RedirectMatch ^/&sa$ /$1? [R=301,L]
or should i use query string for the same??
You can use this rule in your DOCUMENT_ROOT/.htaccess file:
RewriteEngine On
RewriteRule ^([^&]+)& /$1? [L,NE,R=302]
Related
I'm trying to redirect everything under www.mywebsite/asd/ except for three URLs and any subcontent, www.mywebsite/asd/A/, www.mywebsite/asd/B/ and www.mywebsite/asd/A/.
I tried the following pattern, but it seems to be faulty:
RedirectMatch 301 ^/asd/((?!A/|B/|C/).)* /asd/new-target/index.html
The regular expression does what I want, when I test it in a regex editor. But in htaccess it doesn't work. What do I have to change?
You can use this rule:
RedirectMatch 301 ^/asd/(?!A/|B/|C/|new-target/)(.*)$ /asd/new-target/index.html
And test it after clearing your browser cache. Make sure this is your first rule in site root .htaccess and there is no .htaccess in /asd/ directory.
Alternatively you can use this mod_rewrite rule in your site root .htaccess:
RewriteEngine On
RewriteCond %{REQUEST_URI} !^/ads/(?:A|B|C|new-target)/ [NC]
RewriteRule ^/?asd(?:/.*)?$ /asd/new-target/index.html [L,NC,R=301]
I'm trying to alter a part of an URL as below from this type URL ...
/shop/product/41/3030651/Apple-Imac-215-Inches-Me086ba-By-Viking.html
to this ..
/shop/product/1/030651/Apple-Imac-215-Inches-Me086ba-By-Viking.html
where all numbers like 41 are altered to 1 but it seems this code ...
RewriteRule ^product/([^/]+)/([^/]+)/([^/]+)\.html$ index.php?case=product&proddb=$1&pid=$2&urltxt=$3 [L]
is interfering.
I've tried lots of rewrite configurations but nothing seems to work but I do get a reaction from the code below ...
RedirectMatch 301 /shop/product/41/(.*) /shop/product/1/$1
But it must conflict with the RewriteRule above as I get sent to the root of the site.
Have redirect rule before your earlier rewrite rule:
RewriteEngine On
RewriteRule ^product/41/(.+)$ /product/1/$1 [L,NC,R=301]
RewriteRule ^product/([^/]+)/([^/]+)/([^/]+)\.html$ index.php?case=product&proddb=$1&pid=$2&urltxt=$3 [L,QSA,NC]
I have the following pages after enabling pretty urls in my CMS:
www.mydomain.com/cars/
www.mydomain.com/cars/carshome/
www.mydomain.com/cars/honda/
www.mydomain.com/cars/toyota/
...
I want all requests to www.mydomain.com/cars/ to go to www.mydomain.com/cars/carshome/. Thus I've been trying to use in Apache .htaccess file (after pretty urls code executes):
Redirect 301 /cars https://www.mydomain.com/cars/carshome/
and the result is it goes in infinite loop:
(https://www.mydomain.com/cars/carshome/carshome/carshome/...).
How to resolve?
A second question would be, assuming the solution above needs to be changed here: how to redirect the other direction (from www.mydomain.com/trucks/truckshome/ to www.mydomain.com/trucks/)?
Instead of Redirect you can use RedirectMatch directive for its regex capability:
RedirectMatch 301 ^/cars/?$ https://www.mydomain.com/cars/carshome/
This should work for you:
RewriteEngine on
RewriteCond %{REQUEST_URI} !^/cars/carshome/(.*)
RewriteRule ^cars/(.*)$ /cars/carshome/$1 [R=301,L]
The above will check to see if the url contains cars/carshome/ and if it does, then nothing happens, but if it doesn't then it will redirect.
As for the second question, this should work:
RewriteCond %{REQUEST_URI} ^/trucks/truckshome/(.*)
RewriteRule ^trucks/truckshome/(.*)$ /trucks/$1 [R=301,L]
I have several redirects in my htaccess file like
redirect 301 /detail.php?id=101 http://www.example.com/product/costume-didnt-fit-im-stuck-shirt/
I use this method frequently, but this time it seems to not be working and I am thinking it is the dynamic url. Is there a way to have this method of redirect with this type of URL?
You cannot match query string in Redirect directive. Use mod_rewrite rules instead:
RewriteEngine On
RewriteCond %{QUERY_STRING} ^id=[0-9]+
RewriteRule ^detail\.php$ http://www.example.com/product/costume-didnt-fit-im-stuck-shirt/? [L,R=301,NC]
I need to have a redirect done to a site I have that is a 404 error.
Redirects are done in a .htaccess file for Joomla. This is what I have currently:
redirect 301 /?view=category&id=12:bestfriend&Itemid=946&start=20 http://www.mysite.com
But it doesn't redirect because it starts with a "?".
Any ideas? I have a number amount of these like this - not just one.
You cannot match query string using Redirect directive. Use mod_rewrite like this:
RewriteEngine On
RewriteCond %{QUERY_STRING} ^view=category&id=12:bestfriend&Itemid=946&start=20 [NC]
RewriteRule ^ http://www.mysite.com/? [R=301,L]