I've added inm my htaccess this code that I've found on this website: RedirectMatch 301 /en/(.) /$1 and RedirectMatch 301 /it/(.) /$1
My problem was to remove the language from the url, and it worked.
But, because my english homepage is like https://www.mywebsite.it/en/ , when I'm in the english version of the website, and I click the logo to go to homepage, it will redirects to the italian homepage. I dont know how to fix this code adding a rule to not remove "/en/" from the homepage.
Thank a lot.
Related
I needed to remove the language slug from my urls via htaccess:
(ENGLISH) https://www.mywebsite.it/en/art/architecture/
(ITALIAN) https://www.mywebsite.it/it/arte/architettura/
I've found this code into stack:
RedirectMatch 301 /it/(.) /$1
and it worked. The problem is that I have a multilanguage website, and when I do the same thing for the english language adding:
RedirectMatch 301 /en/(.) /$1
when I click on the logo, instead of going to the english home it goes to the italian one. How I can fix this avoiding the removal of the /en/ slug from the english homepage? Thanks a lot.
There was an old site, and all your URLs have changed.
One URL that was well found on Google was:
mydomain.com/datacenters
Now I want to redirect this URL to:
mydomain.com/data-centers
In htaccess I did:
redirect 301 /datacenters /data-centers
But it does not work, what am I doing wrong?
Only work with:
RewriteRule ^datacenters http://mydomain.bla/data-centers [L,R=301,NC]
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 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]