How to 301 redirect from map - html

I made a website where I made an English version as well. The English version map is in /en.
The normal site of mine, redirects with this code:
RewriteCond %{HTTP_HOST} ^www.mysite.nl$ [NC]
RewriteRule ^(.*)$ http://mysite.nl/$1 [R=301,L]
The English version is in the /en map so I thought this would work, but it doesn't.
RewriteCond %{HTTP_HOST} ^www.mysite.nl/en$ [NC]
RewriteRule ^(.*)$ http://mysite.nl/en/$1 [R=301,L]
Does someone know how to 301 redirect when the site is in a folder?

With your shown samples, please try following htaccess Rules. Please make sure to clear your browser cache before testing your URLs.
RewriteEngine ON
##Rules for putting en in uris.
RewriteCond %{HTTP_HOST} ^www\.mysite\.nl$ [NC]
RewriteCond %{REQUEST_URI} !^/en [NC]
RewriteRule ^(.*)/?$ http://mysite.nl/en/$1 [R=301,L]
##Other rules for redirection.
RewriteCond %{HTTP_HOST} ^www\.mysite\.nl$ [NC]
RewriteRule ^(.*)/?$ http://mysite.nl/$1 [R=301,L]

Related

Only the homepage redirects to www version and not the internal pages. Why?

I am trying to redirect all the requests to https www version of the website. Homepage redirects perfectly fine but any other page of the website doesn't. I checked the redirect rules mentioned in the htaccess and they work perfectly fine. However, on the live website, it doesnt.
Here's the redirect rules
RewriteEngine On
RewriteCond %{HTTP_HOST} ^example.com [NC]
RewriteRule ^(.*)$ https://www.example.com/$1 [L,R=301,NC]
Any reason why this is happening?
I tried working through different redirect rules to see which one redirects as per the requirement.
try this
RewriteEngine On
RewriteCond %{HTTP_HOST} !^www\. [NC]
RewriteRule ^(.*)$ http://www.yourSiteName.com/$1 [L,R=301]
RewriteCond %{HTTPS} off
RewriteRule ^(.*)$ https://www.yourSiteName.com/$1 [L,R=301]

I attempted to remove the .html extension from my pages and now when clicked, navigation goes to another site

*This question is unique because I do not need to remove the .html from the file extensions; I need to have internal links function correctly.
My site is http://purplerosecare.com and I tried creating a .htaccess page with the suggested copy/paste from the SO page: How to remove .html from URL
The code I used is below:
RewriteEngine on
RewriteBase /
RewriteCond %{http://www.proofers.co.uk/new} !(\.[^./]+)$
RewriteCond %{REQUEST_fileNAME} !-d
RewriteCond %{REQUEST_fileNAME} !-f
RewriteRule (.*) /$1.html [L]
RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /([^.]+)\.html\ HTTP
RewriteRule ^([^.]+)\.html$ http://www.proofers.co.uk/new/$1 [R=301,L]
(The code & .htaccess have both been removed)
The problem I'm facing is whenever I click on a link in the navigation it sends me to http://www.proofers.co.uk/new/. How can I get the site functional again?
Try this in your Root/.htaccess file
#Remove html extensions from files
RewriteEngine On
RewriteBase /
RewriteCond %{THE_REQUEST} ^[A-Z]{3,}\s([^.]+)\.html [NC]
RewriteRule ^ %1 [R,L]
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}.html -f
RewriteRule ^(.*?)/?$ $1.html [L]

Redirection through htaccess from non html to .html extension?

i want to add .html to my html files automatically using htaccess.
As we can remove .html very easily but i want to know can i add .html to a non html file that is located with my website.
for example this is my domain
www.abc.com/name.html
but when i am accessing
www.abc.com/name
It is showing me the same page but not automatically adding the .html extension.
So i want that if i try to open
www.abc.com/name then it automatically shows me www.abc.com/name.html
How to achieve this.
Thanks
You can use this rule:
RewriteEngine On
RewriteCond %{HTTPS} off [OR]
RewriteCond %{HTTP_HOST} !^www\. [NC]
RewriteRule ^ https://pcsmartcare.com%{REQUEST_URI} [L,R=301]
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME}.html -f
RewriteRule ^(.+?)/?$ /$1.html [L,R=301]
RewriteCond %{THE_REQUEST} /index\.html?\s [NC]
RewriteRule ^(.*)index\.html?$ /$1 [R=301,L,NC]

how to use .htaccess file in our HTML website? for remove page extention from website

I have a HTML website and I want to remove pages extension (.html) from my website. I've used .htaccess file but I don't know how to use .htaccess file in my website's page.
Anybody please help me.
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}\.html -f
RewriteRule ^(.*)$ $1.html
No need to add code in any page.Create .htacess file with above content & add file to the root folder of your site(for example, /home/domains/domain.com/htdocs/)
RewriteEngine On
RewriteCond %{THE_REQUEST} ^GET\ /([^.\ ]+\.)+html(\?[^\ ]*)?\ HTTP
RewriteRule ^(.+)\.html$ http://www.example.com/$1 [R=301,L]
RewriteRule ^([^/]+/)*index/?$ http://www.example.com/$1 [R=301,L]
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)/$ http://www.example.com/$1 [R=301,L]
RewriteCond $1 !^([^.]+\.)+([a-z0-9]+)$ [NC]
RewriteCond %{REQUEST_FILENAME}.html-f
RewriteRule ^(.*[^/])$ /$1.html[L]
RewriteCond %{HTTP_HOST} !^www\.example\.com
RewriteRule (.*) http://www.example/$1 [R=301,L]
Change whole content of .htaccess with above one ,I hope above will helpful.!

htaccess to redirect main domain

I have a htaccess that redirects my main domain "www.main.com" to "www.main.com/DBS2010".
The htaccess works but my url changes to "www.main.com/DBS2010" can I make the url stay as "www.main.com"?
htaccess
RewriteEngine On
RewriteCond %{HTTP_HOST} ^(www.)?main.com$
RewriteRule ^(/)?$ DBS2010 [L]
You can try this code for that:
RewriteEngine On
RewriteCond %{HTTP_HOST} ^(www\.)?main\.com$ [NC]
RewriteRule ^$ DBS2010 [L]
This will not change URL in browser to `/DBS2010'.