I have the following redirection in htacces
Redirect 301 /xxxxxxxxxxxxxxxxxxx.html https://xxxxxxxxxx/yyyyyyyyyy/zzzzzzzzzzzz.html
well this one works properly, however if i try adding more redirections using the same method they dont work, the only difference is that those links does not have .html extension.
Redirect 301 /xxxxxxxxxxxxxxxxxxx https://xxxxxxxxxx/yyyyyyyyyy/zzzzzzzzzzzz
Example:
I have the following url https://estetic4you.com/product/index?brand=Mesoestetic which returns an 404 error, so i use the following code: RedirectMatch 301 ^/product/index?brand=Mesoestetic$ estetic4you.com/14-mesoestetic but still not redirecting. I also tried:
Redirect 301 /product/index?brand=Mesoestetic https://www.estetic4you.com/14-mesoestetic
and it doesnt work
You cannot match query string using Redirect directive.
Use mod_rewrite engine with a separate RewriteCond like this:
RewriteEngine On
RewriteCond %{QUERY_STRING} brand=Mesoestetic
RewriteRule ^product/index/?$ https://www.estetic4you.com/14-mesoestetic? [L,NC,R=301]
Related
I am trying to 301 redirect this URL https://example.com/#guest to https://example.com/forum
I tried this:
Redirect 301 /#guest /forum
Unfortunately It redirects to https://example.com/forum?
You may use this rule with RewriteRule that supports regex and precise matching:
RewriteEngine On
RewriteRule ^#guest /forum? [L,NC,R=301]
Test it after clearing browser cache again.
? in redirected URL will strip off any query string.
This is probably an easy question, but we can not find why the 301 is not working. When we have a url with a question mark the 301 redirect in our .htacces is not working. For example:
/order/order.html?AddID=1078&Rand=666171759380936096
so:
Redirect 301 /order/order.html?AddID=1078&Rand=666171759380936096 http://www.domain.nl
In our webmaster tools we have 8000 url's with the same structure /order/order.html?AddID=.... that say 404 not found. We want to 301 redirect them to the homepage, but we get a 404 not found page instead. when we use the same redirect with only /order/order.html he is redirected correct.
You can't match against the query string in a Redirect statement, use mod_rewrite and match against the %{QUERY_STRING} var:
RewriteEngine On
RewriteCond %{QUERY_STRING} ^AddID=1078&Rand=666171759380936096$
RewriteRule ^order/order.html$ http://www.domain.nl/? [L,R=301]
But since you have like 8000 URLs that start with the query string ?AddID=, then you can just match against that:
RewriteEngine On
RewriteCond %{QUERY_STRING} ^AddID=[0-9]
RewriteRule ^order/order.html$ http://www.domain.nl/? [L,R=301]
I have just tried it again and now I placed it right in the top of the htacces, see printscreen. In this case it is about the url (normally I do not place my own url) www.tablet.nl and if you place one of our 404 pages /order/order.html?AddID=1037&Rand=539054443213186002 behind the url, /order/order.html is deleted and only ?AddID=1037&Rand=539054443213186002 is shown behind the main url with a 404 page not found.
Any idea and I let the htacces as shown in the attachement so you can test the url.
Let me know
I'am trying to update .htaccess to redirect me from : page.php/name to page.php?id=name. Can anyone help with example? I find a lot of example but not for this case.
To redirect (telling the browser that the request for page.php/name is at page.php?id=name, thus changing the URL in the location bar) you can do one of two things.
Using mod_alias:
RedirectMatch 301 ^/page\.php/(.*)$ /page.php?id=$1
Or using mod_rewrite:
RewriteRule ^/?page\.php/(.*)$ /page.php?id=$1 [QSA,L,R=301]
If you don't want a permanent redirect (301), then remove the 301 and =301 parts from the above.
I am having trouble redirecting an entire directory that no longer exists on our server.
All variations of the following are not working and I simply get a 404 Page Not Found.
.htaccess file looks like this:
redirect 301 /non_existent_directory/ http://my.website.com/existent_directory/
Is it possible to use the Redirect 301 directive for this? Or is this only solvable by mod_rewrite?
Thanks
I even tried:
Options +FollowSymLinks
RewriteEngine On
RewriteCond %{HTTP_HOST} ^(www\.)?my\.website\.com\/non_existent_directory\/$ [NC]
RewriteRule ^(.*)$ http://my.website.com/existent_directory/ [R=301,L]
No luck...
From the Redirect documentation, I would say
Redirect 301 /non_existent_directory http://my.website.com/existent_directory
or
Redirect 301 /non_existent_directory /existent_directory
should work, provided you are allowed to use this in a .htaccess file. See also Troubleshooting .htaccess files. You should test without 301 though, to prevent caching of bad redirects by the client.
If this doesn't work, you can try a RewriteRule of course
RewriteEngine On
RewriteRule ^/?non_existent_directory(.*)$ /existent_directory$1 [R,L]
But this is equivalent to the above Redirect directive.
IS there a way with just htaccess 301 redirect to redirect any page on a domain to a specific page on another domain.
eg. I was domain.com/index.html and domain.com/contact.html to both redirect to newsite.com/index.html
But I am wanting to do this without having to list each of the pages specifically.
can my 301 redirect be just something like
301 * http://newsite.com/index.html
or how should it be set up. Unfortunately I don't have access to mod rewrite so I cant use mod rewrite to make it work.
Had an issue similar to this using wordpress and trying to remove all .asp extensions from pages, this worked pasted at the top of my .htaccess file
## 301 Redirects
RewriteCond %{QUERY_STRING} ^$
RewriteRule ^(.*)\.asp$ $1? [R=301,NE,NC,L]
Yes, that is possible -- instead of mod_rewrite you need to use mod_alias (which has more chances to be enabled).
This one will redirect everything to index.html on newsite.com/
RedirectMatch 301 ^/(.*)$ http://newsite.com/index.html
This one will redirect everything to the same path but on another domain: (e.g. oldsite.com/meow.php => newsite.com/meow.php)
RedirectMatch 301 ^/(.*)$ http://newsite.com/$1