I want to make a redirection from an old URL https://www.mywebsite.eu/en/form/emsos-2017/ to the homepage https://www.mywebsite.eu/.
I do not have access to the webserver but I know that the language prefix (in this case /en) is managed by the CodeIgniter framework.
mod_alias and mod_rewrite are enabled.
So I already tried that but none worked.
Redirect https://www.mywebsite.eu/en/form/emsos-2017 https://www.mywebsite.eu
RewriteRule ^emsos-2017/ https://www.mywebsite.eu [R=301,L]
RedirectMatch 301 ^/emsos-2017$ http://www.mywebsite.eu
I know that the .htaccess is read because when I make a typo I have an Internal Server Error.
I also tried to redirect 404 error but this is not working.
ErrorDocument 404 https://www.mywebsite.eu/404/
You need to give full URI without domain name in pattern of RedirectMatch.
Try this rule before any other rule in site root .htaccess:
RedirectMatch 301 ^/[a-z]{2}/form/emsos-2017/?$ /
Related
I'm setting up a project where users can get information about specific pages.
How can I redirect urls in htaccess that look like:
http://www.example.com/http://www.cnn.com/article1.html
to:
http://www.example.com/cnn/article1.html
It is ok if the htaccess specifies cnn and not all dynamic web addresses.
I tried using 301 directory redirects but I think the "http://" part of it is confusing it.
I tried using 301 directory redirects like the following code, but the http:// part is still confusing it:
RewriteRule ^http://youtube.com/(.*)$ /youtube/$1 [L,R=301]
RewriteRule http://www.example.com/http://youtube.com/(.*)$ /youtube/$1 [L,R=301]
This code below works properly to redirect example.com/youtube.com/watch?v=videoid to example.com/youtube/watch?v=videoid:
RewriteRule ^youtube.com/(.*)$ /youtube/$1 [L,R=301]
but if the user types in a link with http:// in it then the server cannot currently redirect properly.
Even better, if you can remove the /http:// and /https:// altogether from http://example.com/http://url.com and http://example.com/https://url.com to redirect to http://example.com/url.com/ then the redirect code that I have working in the youtube example will fix the issue for all of the domains.
How can I do this?
Thank you!
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 want to apply 301 redirection on domain so that we can redirect our users to http://domain.com/page/about.
htaccess:
Redirect 301 Domain Domain/page/about
Url adding continue page/about in URL
http://domain.com/page/aboutpage/aboutpage/aboutpage/aboutpage/aboutpage/aboutpage/aboutpage/aboutpage/aboutpage/aboutpage/aboutpage/aboutpage/aboutpage/aboutpage/aboutpage/aboutpage/aboutpage/aboutpage/aboutpage/aboutpage/about
Browser Error:
Warning: glob() [function.glob]: Pattern exceeds the maximum allowed length of 260 characters.
Please advice me.
Thanks
The Redirect directive links two path nodes, so when you start with Redirect /path /something/something, it redirects every URI that starts with /path. Which means a request like http://domain/path/some/other/path gets redirected to /something/something/some/other/path. So you can't use Redirect for what you're doing. You can try RedirectMatch:
RedirectMatch 301 ^/$ /page/about
Or, alternatively, using mod_rewrite:
RewriteEngine On
RewriteRule ^/?$ /page/about [L,R=301]
I'm having a problem getting an old WordPress site page to redirect to the new basic PHP site page.
Example: The old WordPress page with no extension is at http://example.com/levelone/leveltwo/pagename
The new page is at http://example.com/directory/pagename.php.
Here are several things I've tried:
redirect 301 /levelone/leveltwo/pagename http://example.com/directory/pagename.php
This did not work at all
Then I tried redirecting the directories first, then the page, like so:
RedirectMatch 301 ^/levelone/leveltwo/ http://example.com/directory/
redirect 301 /pagename http://example.com/pagename.php
This almost worked, but gave me the right URL but without the PHP extension.
I can't just redirect an old directory to a new one because there are actually many. The example is just one. The trouble seems to be going from a non-extension page to a page with the .php extension.
Here's another thing I tried:
RedirectMatch 301 ^/levelone/leveltwo/(.*)$ /directory/$1.php
redirect 301 /pagename http://example.com/pagename.php
This gave me http://example.com/directory/pagename/.php.
Solved: I got it to work with the following:
Redirect 301 /levelone/leveltwo/pagename/ http://example.com/directory/pagename.php
The problem seemed to be with the missing forward-slash after the old page name.
Try:
RedirectMatch 301 ^/levelone/leveltwo/(.*)$ /directory/$1.php
What's probably happening is the mod_alias and mod_rewrite aren't playing nice with each other. They're both in the URI-file mapping pipeline so when one does its processing, the URI (eventhough a redirect response is what's going to ultimately happen) continues to get processed, then when the redirect happens, the URI has been mangled by mod_rewrite.
You should just stick with mod_rewrite so that you can prevent any wordpress rules from doing its thing. Add these rules above any wordpress rules you have in your htaccess file:
RewriteEngine On
RewriteRule ^/?levelone/leveltwo/(.*)$ /directory/$1.php [L,R=301]
I need to redirect all the old URLs on my site to new URLs, but am having issues. A given URL and its subfolders need redirecting to the same page.
For example, this is the first one:
redirect 301 /panache/sports-bra/ http://www.newdomain.co.uk/sports-bra.html
This works ok. However there are these size sub-pages which need to redirect to the same location:
redirect 301 /panache/sports-bra/30DD http://www.newdomain.co.uk/sports-bra.html
redirect 301 /panache/sports-bra/30E http://www.newdomain.co.uk/sports-bra.html
redirect 301 /panache/sports-bra/30F http://www.newdomain.co.uk/sports-bra.html
And these don't work, I end up at a location like the following:
http://www.newdomain.co.uk/sports-bra.html30DD
See the way the last part of the path is appended to the url? I'm guessing it's because the second redirect is conflicting with the initial 301 redirect?
I have also tried using this rewrite rule but have had no luck. The site is Magento so I don't know if this has some effect? mod_rewrite is enabled on the server.
RewriteRule ^panache/sports-bra/ http://www.newdomain.co.uk/sports-bra.html [R=301]
Any help mucha ppreciated.
Try this.
RewriteEngine on
RewriteRule ^(panache/sports-bra/.*)$ /sports-bra.html [L,R=301,NC]