Is there any way of making a 301 redirect from:
/#done
to
/bin
I currently have this code situated in my .htaccess file:
Redirect 301 /#done /bin
But it does not redirect because of the illogical placement of the #, within the statement, is there any way to overcome this? With the resulting URL still redirecting from the address of example.com/#done?
Thanks
The # character is a reserved character in URLs according to RFC3986.
You could try whether it helps to use the character's encoded representation %40 instead.
Update
You could create the folder #done at the proper place of the webserver and put an index.php file in it. This will redirect all requests from /#done to /bin.
<?php
header('HTTP/1.1 301 Moved Permanently');
header("Location: /bin");
header("Connection: close");
?>
Related
I have to manually redirect few URLs in my website1 to website2.
Below is my code in the .htaccess file of website1
Redirect 301 /post1/ https://www.website2.com/post1
When I enter https://www.website1.com/post1/ in the browser it's being redirected to https://www.website2.com/post1 successfully, as expected.
But, When I enter https://www.website1.com/post1 in the browser it's being redirected to https://www.website2.compost1, the slash is missing after https://www.website2.com
What could be done to solve this?
You can do this in a single rule using RedirectMatch that uses a regex to make trailing slash optional as this:
RedirectMatch 301 ^/(post1)/?$ https://www.website2.com/$1
Added benefit is avoiding repeat of post1 in source and target by using a capture group in source and using back-reference $1 in target.
Remove the trailing / from the Redirect.
Redirect 301 /post1 https://www.website2.com/post1
This redirect then works for both versions of the URL. See testing link here.
Using 2 Redirect URLs in this particular order solved it.
Redirect 301 /post1 https://www.website2.com/post1
Redirect 301 /post1/ https://www.website2.com/post1
I do not understand htaccess fully so I need help solving this. I need to redirect users from the directory www.example.com/es and www.example.com/en to the subdirectory www.example.com/old/es and www.example.com/old/en.
Add this in the htaccess file in your document root:
RedirectMatch 301 ^/(en|es)(/.*)?$ /old/$1$2
If you only want to redirect /en and /es, and not /en/foo or /es/something/else then remove the $2 bit from the end.
i want to redirect a page:
http://www.mysite.com/samplepage/
Pages like http://www.mysite.com/samplepage/samplepage2/ shall not be redirected.
This is my current .htaccess code:
RedirectMatch 301 ^/samplepage/ /new-samplepageurl
The problem:
This one also redirects url's like:
http://www.mysite.com/samplepage/samplepage2/
Can I limit the redirect only to that one exact path?
Try using this:
RedirectMatch 301 ^/samplepage/?$ /new-samplepageurl
The $ sign marks the end of string, and ? mark makes the trailing slash opional (e.g. both /samplepage and /samplepage/ will be redirected)
Given the following path:
http://www.testsite.com/some/path/
I want to redirect it to
http://www.testing.com/new/stuff/
How can I make .htaccess execute that redirect regardless of whether the path has a trailing slash or not?
Edit
I've tried this:
RedirectMatch 301 /some/path(.*) /new/stuff/$1
However, it results in the following redirect
http://www.testing.com/new/stuff/?/some/path
how can I make redirect from one path to another without appending anything to the new path. I just want it to go to '/new/stuff/' with nothing on the end regardless of what, if anything, comes after '/some/path'
Just remove the $1 from your RedirectMatch's target. You should also include the ^ for the beginning of the URI:
RedirectMatch 301 ^/some/path(.*) /new/stuff/
Putting this at the top of my htaccess file doesn't do anything:
Redirect 301 /taxonomy/term/6%207%208%209 http://mysite.com/taxonomy/term/all
Neither does this:
Redirect 301 http://mysite.com/taxonomy/term/6%207%208%209 http://mysite.com/taxonomy/term/all
Im using a CMS that uses its own htaccess file so could it be my rule are being overridden? I thought that putting the code at the top of the file would solve this? Thanks
Escapes get decoded before going through mod_alias, so the %20's get turned back into spaces. You need to put them in quotes:
Redirect 301 "/taxonomy/term/6 7 8 9" http://mysite.com/taxonomy/term/all