How can i remove /home from my website url so that my site can only be accessed by mywebsite.com and mywebsite.com/home redirected to mywebsite.com
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php?/$1 [L]
#301 redirect
RewriteCond %{HTTP_HOST} ^www.mywebsite.com$ [NC]
RewriteRule ^(.*)$ http://mywebsite.com/$1 [R=301,L]
</IfModule>
Add this right below RewriteEngine On
RewriteCond %{THE_REQUEST} ^.*/home
RewriteRule ^(.*)home$ http://yourwebsite.com/$1 [R=301,L]
Related
Currently only the homepage is redirecting from www.example.com and example.com to https://example.com
I try to redirect:
1. http://www.example.com/otherpages to https://example.com/otherpages
2. http://example.com/otherpages to https://example.com/otherpages
3. https://www.example.com to https://example.com
3. https://www.example.com/otherpages to https://example.com/otherpages
Tried to use some former questions but can't figure it out.
current state in .htaccess is:
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
RewriteCond %{SERVER_PORT} 80
RewriteRule ^(.*)$ https://my-domain.com/$1 [R=301,L]
RewriteCond %{HTTP_HOST} ^www\.(.*)$ [NC]
RewriteRule ^(.*)$ https://%1/$1 [R=301,L]
RewriteCond %{HTTP_HOST} ^www\.my\-domain\.com [NC]
RewriteRule ^(.*)$ http://my-domain/$1 [L,R=301]
</IfModule>
Thanks in advance
You don't need all that code for the conditions you want. Replace your all of that code with this and change to your domain.
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteCond %{HTTPS} !^on [OR]
RewriteCond %{HTTP_HOST} !^example\.com$ [NC]
RewriteRule ^(.*)$ https://example.com/$1 [R=301,L]
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>
I have pages with redirecting to www.homage.com/index.php.
It should be redirecting to the www version. here my Htaccess File:
<IfModule mod_rewrite.c>
Options +FollowSymLinks
RewriteEngine on
RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}]
RewriteCond %{REQUEST_URI} !^/(media|skin|js)/
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-l
RewriteRule ^(.*)$ index.php/$1 [L]
</IfModule>
# Redirect non-www urls to www
RewriteEngine on
RewriteCond %{HTTP_HOST} !^www\.mindscopeproducts\.com
RewriteRule (.*) http://www.mindscopeproducts.com/$1 [R=301,L]
Have it this way:
Options +FollowSymLinks
RewriteEngine on
RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}]
# Redirect non-www urls to www
RewriteEngine on
RewriteCond %{HTTP_HOST} !^www\. [NC]
RewriteRule ^ http://www.mindscopeproducts.com%{REQUEST_URI} [R=301,L]
RewriteCond %{REQUEST_URI} !^/(media|skin|js)/
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-l
RewriteRule ^(.*)$ index.php/$1 [L]
i.e. keep external redirect rule before other forwarding rules. Make sure to clear your browser cache when testing this.
Reorder your rules like this :
<IfModule mod_rewrite.c>
RewriteEngine on
Options +FollowSymLinks
#Redirect non-www urls to www
RewriteCond %{HTTP_HOST} !^www\.mindscopeproducts\.com$
RewriteRule ^(.*)$ http://www.mindscopeproducts.com/$1 [R,L]
RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}]
RewriteCond %{REQUEST_URI} !^/(media|skin|js)/
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-l
RewriteRule ^(.*)$ index.php/$1 [L]
</IfModule>
I have the Q2A script installed http://www.question2answer.org/
I have non-www. & non-https redirecting to www & https perfectly but, somewhere within the htaccess code it's redirecting my add-on domain http://addon-domain.com to https://www.main-domain.com/addon-domain.com/
I suspect it's something to do with the following but, have no idea how to edit it correctly:
RewriteCond %{REQUEST_URI} ^(.*)//(.*)$
RewriteRule . %1/%2 [R=301,L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^.*$ index.php?qa-rewrite=$0&%{QUERY_STRING} [L]
Here's the whole code:
DirectoryIndex index.php
<IfModule mod_rewrite.c>
RewriteEngine On
#RewriteBase /
# redirect any domain other than www.main-domain.com to www.main-domain.com
RewriteCond %{HTTP_HOST} !^www\.main-domain\.com$ [NC]
RewriteRule ^(.*)$ https://www.main-domain.com/$1 [L,R=301]
# force https on www.main-domain.com
RewriteCond %{HTTPS} ^off
RewriteRule ^(.*)$ https://www.main-domain.com/$1 [L,R=301]
RewriteCond %{REQUEST_URI} ^(.*)//(.*)$
RewriteRule . %1/%2 [R=301,L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^.*$ index.php?qa-rewrite=$0&%{QUERY_STRING} [L]
</IfModule>
I need to make this work with HTTP, HTTPS and SSL, this is my actual (working) rewrite:
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)$ index.php?url=$1 [L,QSA]
</IfModule>
But i Need to force to redirect the non "www" urls (like http://domain.com) to the same URL with the "www" AND still working the index.php?url=$1 because i need this for my "router" engine.
Thanks for the help!
This should do the work (before any other rewrite rule):
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{HTTPS} !=on
RewriteCond %{HTTP_HOST} !^www.*$
RewriteRule ^(.*)$ http://www.%{HTTP_HOST}/$1 [L,R=301]
RewriteCond %{HTTPS} =on
RewriteCond %{HTTP_HOST} !^www.*$
RewriteRule ^(.*)$ https://www.%{HTTP_HOST}/$1 [L,R=301]
RewriteRule ^(.*)$ index.php?url=$1 [L,QSA]
</IfModule>
Just add the non-www to www rule at the beginning, like this:
#non-www to www
RewriteEngine On
RewriteCond %{HTTP_HOST} ^domain\.com/?$ [NC]
RewriteRule ^(.*)$ http://www.domain.com/$1 [L,R=301]
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)$ index.php?url=$1 [L,QSA]
</IfModule>
I am trying to add a "/login" to wildcard subdomains.
For example:
*.example.com would be redirected to *.example.com/login
but, i want certain subdomains not to be redirected, such as...
help.example.com, m.example.com, etc.
What is the best way to do this, and would this be done in .htaccess or in httpd.conf?
Thank you for your help.
Updated below:
Here is what I currently have:
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteCond %{HTTP_HOST} !^m.example.com$
RewriteCond %{HTTP_HOST} ^(.+).example.com$ [NC]
RewriteRule ^/$ https://%1/login [L,R=301]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/$1 [L]
</IfModule>
You were almost there
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteCond %{HTTP_HOST} !^m\.example\.com$
RewriteCond %{HTTP_HOST} !^help\.example\.com$
RewriteCond %{HTTP_HOST} ^(.+\.example\.com)$ [NC]
RewriteRule ^/?$ https://%1/login [L,R=301]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/$1 [L]
</IfModule>