htaccess to redirect main domain - html

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'.

Related

Website links won't work with .htaccess code which removes .html extension

I have the following code in my .htacess file for my website to remove '.html' from my urls and to redirect any .html to the same page without it (example.com/home.html to example.com/home)
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)\.html$ /$1 [L,R=301]
#301 from example.com/page.html to example.com/page
RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /.*\.html\ HTTP/
RewriteRule ^(.*)\.html$ /$1 [R=301,L]
However, when I try to click on links that are pointed to other pages on my website, I get a 404 error.
I've tried setting the href to http://www.example.com/page2, /page2 and more but I still get the same error. Any help?
Please save your code and put only the following code in your main directory .htaccess file :
RewriteEngine on
RewriteCond %{THE_REQUEST} \s/+(.*?/)?(.*?)\.html[\s?/] [NC]
RewriteRule (.*)$ /%1%2 [R=302,L,NE]
Note: clear your browser cache because you did 301 redirect and test the code

How to redirect website.com/ and website.com/index.php to another page with htaccess

I can redirect website.com/index.php to website.com/home but I can't find a way to redirect website.com to website.com/home
I have tried RewriteRule ^/$ /home [R=301] but it does nothing.
A single rule can handle both redirects:
RewriteRule ^/?(index\.php)?$ /home [NC,L,R=301]
Try this
RewriteEngine on
RewriteBase /
RewriteCond %{HTTP_HOST} ^(www\.)?website\.com$ [NC]
RewriteRule .* http://www.website.com/home [R=301,L]
This rule redirects www.website.com to www.website.com/home
Or add this to your .htaccess
RewriteRule ^/?$ /home [R=301,L]

How to redirect using .htaccess file that redirects from clear domain to www.?

How to redirect:
from mydomain.pl to www.mydomain.pl/start
and
from www.mydomain.pl to www.mydomain.pl/start using .htaccess file?
This should not interfere with any other page. Eg. when somebody types mydomain.pl/contact this should only add www. before the domain.
You can place this rule in your DOCUMENT_ROOT/.htaccess file:
RewriteEngine On
RewriteBase /
RewriteCond %{HTTP_HOST} ^mydomain\.pl$ [NC]
RewriteRule ^ http://www.%{HTTP_HOST}%{REQUEST_URI} [L,NE,R=301]
RewriteCond %{HTTP_HOST} ^(www\.)?mydomain\.pl$ [NC]
RewriteRule ^$ http://www.mydomain.pl/start [L,R]

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.!