Showing "mydomain.com" if I enter "mydomain.com/index.htm" - .htaccess

Like most servers, if I enter: www.mydomain.com, my server shows www.mydomain.com/index.htm and my Browser continues to show www.mydomain.com
But if I enter into my Browser www.mydomain.com/index.htm, can I tweak htaccess to show www.mydomain.com in my Browser?

You can use the following
RewriteEngine on
RewriteCond %{THE_REQUEST} /index\.htm [NC]
RewriteRule ^ / [L,R]

Related

Subdomain redirects to subdomain.domain.com/subdomain

I have some really strange behavior on my subdomain.
When i enter my url in get redirected to a folder inside the subdomain.
For example:
When i enter: subdomain.domain.nl I get redirected to: subdomain.domain.nl/subdomain
I think is has something to do with this line of code inside my .htaccess
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteCond %{HTTPS} !=on [NC]
RewriteRule ^(.*)$ https://%{HTTP_HOST}/$1 [R=301,L]
</IfModule>
But I don't really know what to change so everything keeps redirected to https and i get rid of the redirecting inside the subdomain.

Htaccess too many redirects only for wordpress blog

I have follwing htaccess for redirecting to www, https and index.html to /:
RewriteEngine On
RewriteCond %{HTTPS} off
RewriteRule (.*) https://%{HTTP_HOST}%{REQUEST_URI} [R=301,L]
RewriteCond %{HTTP_HOST} !^www\. [NC]
RewriteRule ^(.*)$ http://www.%{HTTP_HOST}/$1 [R=301,L]
RewriteBase /
RewriteRule ^index\.html$ / [NC,R,L]
On the website I use a wordpress blog on /blog, which gives this error if I try to access it:
ERR_TOO_MANY_REDIRECTS
I can fix this by swaping the rule order, first comes redirect to www and then https, but then the redirect to www does not work
Okay I found the issue. As a programmer you really should check from time to time what people who have some access to site settings are doing.
In the wordpress login for the admin in settings -> general a custom domain was entered which was https://example.com/blog etc. which means wordpress blog redirected back to the version without www.
The fix is to add www to the wordpress setting.

Force "https" and "www" redirect - Wordpress

Force "https" and "www" redirect
I am trying to see if there is a way to redirect url to https://www.example.com
For example, if people are entering the url http://example.com/subfolder, then it should redirect to https://www.example.com/subfolder.
This is a Wordpress website. If I go to Settings => General => I see WordPress Address(URL) and Site Address (URL) are grayed out so I can't enter any url. Both shows as http://example.com
I went to phpMyAdmin=> option table to change the WordPress Address (URL) and Site Address (URL) to https://www.example.com but I still see the http://example.com on my wordpress general setting panel.
I looked at the wp-config file and found the following code that appears to be preventing me from entering custom url.
define('WP_HOME', 'http://' . $_SERVER['HTTP_HOST']);
define('WP_SITEURL', 'http://' . $_SERVER['HTTP_HOST']);
define('WP_CONTENT_URL', '/wp-content');
define('DOMAIN_CURRENT_SITE', $_SERVER['HTTP_HOST']);
It seems like the WordPress Address(URL) and Site Address(URL) are enforced by the codes here.
My hosting provider recommanded using htaccess to enforce the ssl by putting the code below:
#Force SSL on entire site
RewriteEngine On
RewriteBase /
RewriteCond %{ENV:HTTPS} !on [NC]
RewriteRule ^(.*)$ https://(YOURDOMAIN)/$1 [R,L]
But this guide doesn't really tell us how to enforce www as well.
I found another guide here .htaccess - how to force "www." in a generic way? that explains how to enforce domain.com to www.domain.com. This one supposedly also check https and implement to the rewrite rule.
RewriteEngine On
RewriteCond %{HTTP_HOST} !^$
RewriteCond %{HTTP_HOST} !^www\. [NC]
RewriteCond %{HTTPS}s ^on(s)|
RewriteRule ^ http%1://www.%{HTTP_HOST}%{REQUEST_URI} [R=301,L]
Now, someone else is recommanding the following code below, claiming that the first one above will only work if you want all sub-domains forwarded to www.yourdomain.com. I am just confused which one I need to choose?
RewriteEngine On
RewriteCond %{HTTP_HOST} ^example.com [NC]
RewriteCond %{HTTP_HOST} !^www\. [NC]
RewriteCond %{HTTPS}s ^on(s)|
RewriteRule ^ http%1://www.%{HTTP_HOST}%{REQUEST_URI} [R=301,L]
I am trying to see which option would be the best solution to implement the force redirect? Or should I get rid of those four define() codes from wp-config file so I can setup redirect with wordpress general setting?

How to display one site or page, but show different URL using htaccess?

I want to display aaa.com/test.php, but show bbb.com in the browser's URL field. According to this site, I should use the following in the .htaccess file on aaa.com:
RewriteEngine on
RewriteCond %{HTTP_HOST} bbbs.com$ [NC]
RewriteRule ^(.*)$ /test.php [R=301,L]
However, when I visit aaa.com/test.php there is no re-direct to follow. It still shows aaa.com/test.php.
This was as simple as using a RewriteRule with the [P] proxy flag, which causes the request to be handled by mod_proxy.
RewriteEngine on
RewriteRule ^(.*)$ http://destinationdomain.com/$1 [P]

Subdomain Redirect

I want write a rule in .htaccess for redirecting
http://www.dir.domain.com
http://dir.domain.com
http://www.domain.com/dir
these should redirect to
http://domain.com/dir
Thanks in advance...
The trick here is to use an .htaccess file in your DOCROOT
RewriteEngine on
RewriteBase /
RewriteCond %{HTTP_HOST} ^(www\.)?dir\.domain\.com$
RewriteRule ^.* http://domain.com/dir/$0 [R=301,L]
RewriteCond %{HTTP_HOST} ^www\.domain\.com$
RewriteRule ^dir/.* http://domain.com/$0 [R=301,L]
Note that this is doing a 301 redirect -- that is the server tells the browser that this is a permanent redirect and the browser caches this redirect.
You can also do an internal redirect where this mapping is done silently at the server end by tweaking flags.
This assumes that your shared service is using Apache, if its using IIS, then you need to do something similar with the web.config
You can try:
RewriteCond %{HTTP_HOST} ^((?!www).+)\.domain\.com$
RewriteRule ^ http://domain.com/%1 [L,NE]
Please change domain by your domain, when you enter sub1.domain.com then it will redirect to domain.com/sub1, when you enter sub2.domain.com then it will redirect to domain.com/sub2 ....

Resources