From .htacces file, how to pass/redirect the FULL URL to another URL as GET Variable?
Like:
http://www.test.com/foo/bar.asp
will be redirected to:
http://www.newsite.com/?url=http://www.test.com/foo/bar.asp
With Full Url with Domain.I tried:
RewriteEngine on
RedirectMatch 301 ^/(.*)\.asp http://www.newsite.com/?url=%{REQUEST_URI}
But it is going out like:
http://www.newsite.com/?url=?%{REQUEST_URI}
RewriteEngine on
RedirectMatch 301 ^/(.*)\.asp http://www.newsite.com/?url=$1.asp
If the initial domain and protocol is always the same then you can use
RedirectMatch 301 ^/(.*)\.asp http://www.newsite.com/?url=http%3A%2F%2Fwww.test.com%2F$1\.asp
Related
My redirect is as follows:
Redirect 301 / http://testsite.com/en/
I get the following address: testsite.com/en/en/en/en/en/en/en/en
I worked in a .htaccess file. Where is my mistake?
You should use RedirectMatch to target precise URL using regex:
RedirectMatch 301 ^/$ http://testsite.com/en/
Make sure to test this after clearing your browser cache.
I am working on a site that uses such a url
www.domain.com/hotels/hotel-name
I would like visitors just to see
www.domain.com/hotel-name
This can probably be done in the .htaccess file with a rewrite condition but I don't know how.
Thank you for helping
You can use RedirectMatch directive :
Put the following Redirect above other rules in your htaccess file
RedirectMatch 301 ^/hotels/([^/]+)/?$ /$1
This example would redirect all files from the /hotels/ folder, if you want to redirect a particular file from that folder , you can use the following:
RedirectMatch 301 ^/hotels/(file_name)/?$ /$1
Now if a visiter enters www.example.com/hotels/hotel-name then will be externally redirected to www.example.com/hotel-name
I'm trying to 301 redirect from '/en' or '/en/' to '/en/home' using .htaccess, but any attempt I do results into a redirection loop '/en/home/home/home/home/home/home...'.Shouldn't it be as simple as Redirect 301 /en /en/home?
Redirect based rule keep matching /en in redirected URL as well. You can use RedirectMatch for this with regex support:
RedirectMatch 301 ^/(en)/?$ /$1/home
Also make sure to clear your browser cache when you test this.
You have to use the full URL, example:
redirect 301 /folder_wrong/name.html http://website.com/folder-right/name.html
I have old URLs in my site and looks like this
http://www.example.com/forum/index.php/topic/
I want to redirect it to
http://'www.example.com/forum/index.php?/topic/
Try:
RedirectMatch 301 ^/forum/index\.php(/.+) /forum/index.php?$1
I have urls like these:
http://domain.com/test/MzA5
http://domain.com/test/AtbC
http://domain.com/test/4gCA
How to make htaccess rule which will redirect all urls like http://domain.com/test/[hash here] to one page, for example http://domain.com/page.html
Try:
Redirect 301 /test/MzA5 /page.html
If you have a lot of those hashes, you can make a lot of 301 redirects:
Redirect 301 /test/MzA5 /page.html
Redirect 301 /test/AtbC /page.html
Redirect 301 /test/4gCA /page.html
or consider using a RewriteMap (which requires access to the server config, won't work in .htaccess file)
To redirect all URLs of the form /test/*/ to page.html, use the following rewrite:
RewriteEngine On
RewriteRule ^/test/[^/]+/? /page.html [R=301, L]