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>
Related
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php?/$1 [L,QSA]
RewriteCond %{HTTPS} off
RewriteRule .* https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
RewriteCond %{HTTP_HOST} !^www\. [NC]
RewriteRule .* https://www.%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
</IfModule>
I have created a website using Codeigniter framework and my domain and hosting is on GoDaddy. Now, I have installed SSL certificate and manage with my website. Now, when I use example.com in URL it redirects me on https://www.example.com but when I click on my login page it shows me Not Found and URL looks like https://www.example.com/index.php?/login but I want URL Like https://www.example.com/login. So, How can I do this? Please help.
Thank You
Change order of your rules
Have a single rule to redirect www and http -> https
Your .htaccess should be like this:
RewriteEngine on
# redirect for adding www and https
RewriteCond %{HTTPS} !on [OR]
RewriteCond %{HTTP_HOST} !^www\. [NC]
RewriteRule ^ https://www.%{HTTP_HOST}%{REQUEST_URI} [R=301,L,NE]
# front controller
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php?/$1 [L,QSA]
Make sure to use a new browser for your testing.
Please use this htaccess rules will work 100%
RewriteEngine on
RewriteCond $1 !^(index\.php|resources|robots\.txt)
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php?/$1 [L,QSA]
RewriteCond %{HTTPS} off
RewriteRule .* https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
RewriteCond %{HTTP_HOST} !^www\. [NC]
RewriteRule .* https://www.%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
use this:
Options All -Indexes
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/$1 [L]
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]
I have the following .htaccess file in my subdomain.
My website has http://hello/forum/index.php, and would like to hide this index.php file, and make it http://hello/forum.
Whenever I use the attached .htaccess, it directs to http://hello, not http://hello/forum. Am I missing something?
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteCond %{THE_REQUEST} ^GET.*index\.php [NC]
RewriteCond %{REQUEST_URI} !/system/.* [NC]
RewriteRule (.*?)index\.php/*(.*) forum/$1$2 [R=301,NE,L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ forum/index.php/$1 [L]
</IfModule>
Try these rules:
RewriteCond %{THE_REQUEST} ^GET\ /(forum)/index\.php [NC]
RewriteRule ^ /%1 [R=301,L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ /forum/index.php/$1 [L]
I was able to solve this issue by adding
DirectoryIndex index.php index.html
in .htaccess file.
I'm trying to exclude few URI from htaccess based redirection
My htaccess directives are bellow
<IfModule mod_rewrite.c>
RewriteEngine on
#
RewriteCond %{HTTP_HOST} ^(www\.)?domain1.com$ [NC]
RewriteRule !=/test$ http://domain2.com [L,R=301,NC]
#
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI} !=/favicon.ico
RewriteRule ^(.*)$ index.php?q=$1 [L,QSA]
</IfModule>
What wrong in this? Any suggesion?
I have tried in a different way as well
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteCond %{REQUEST_URI} !=/test
RewriteRule (.*) http://domain2.com? [R=301,L]
# Rewrite URLs of the form 'x' to the form 'index.php?q=x'.
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI} !=/favicon.ico
RewriteRule ^(.*)$ index.php?q=$1 [L,QSA]
</IfModule>
While doing external redirection, exclusion of the the URI, test is not in effect. If I'm doing an internal rewrite, its working fine.
Maybe this works:
Options +FollowSymlinks
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteCond %{REQUEST_URI} !/test
# Add next line
RewriteCond %{REQUEST_URI} !index\.php [NC]
RewriteRule (.*) http://domain2.com? [R=301,L]
# Rewrite URLs of the form 'x' to the form 'index.php?q=x'.
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI} !=/favicon.ico
RewriteRule ^(.*)$ index.php?q=$1 [L,QSA]
</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>