I have a domain mudomain.com.ar and want to redirect all incoming traffic to mudomain.com
I've tried this code:
RewriteEngine On
RewriteCond %{HTTP_HOST} ^www.mudomain.com.ar$ [NC]
RewriteRule ^(.*)$ http://www.mudomain.com/$1 [R=301,L]
This rule redirects all traffic correctly. For example:
mudomain.com.ar/hello/ to mudomain.com/hello/
All traffic except traffic incoming to mudomain.com.ar/ar/
It seems like the .ar/ar/ in the domain is preventing the regex to work, but I can't understand why. Ideas?
Edit:
/ar/ contains the .htaccess
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteRule ^$ webroot/ [L]
RewriteRule (.*) webroot/$1 [L]
</IfModule>
And the webroot directory contains the .htaccess
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ index.php [L]
</IfModule>
If you're using Apache 2.4 then add this line after RewriteEngine On line in your site root .htaccess:
RewriteOptions InheritDownBefore
Read more about RewriteOptions
Related
I have the following .htaccess inside webroot directory:
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{REQUEST_URI} !^(/admin/)
RewriteRule ^$ public/ [L]
RewriteRule (.*) public/$1 [L]
</IfModule>
Then, inside public directory I have the following .htaccess
<IfModule mod_rewrite.c>
RewriteEngine On
# Allow any files or directories that exist to be displayed directly
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)/?$ index.php?$1 [QSA,L]
# Force HTTPS
RewriteCond %{HTTPS} !on
RewriteRule (.*) https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
</IfModule>
Then, if I hit the following URL:
http://example.com/
The browser is redirected to:
https://example.com/public/
When site is loaded over HTTP (without forcing), this part is omitted.
Force https rule must be placed in root .htaccess:
<IfModule mod_rewrite.c>
RewriteEngine On
# Force HTTPS
RewriteCond %{HTTPS} !on
RewriteRule ^ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301,NE]
RewriteRule ^$ public/ [L]
RewriteCond %{REQUEST_URI} !^(/admin/)
RewriteRule (.*) public/$1 [L]
</IfModule>
Remove http->https rule from public/.htaccess and clear browser cahce to test this.
My site is running on cakephp 2.0 version , I want to block some of my site urls.
for example
www.exmaple.com/users/register
www.example.com/users/login
I tried to modify the .htaccess file of root , as well inside app folder but nothing work.
my code is
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteRule ^$ app/webroot/ [L]
RewriteRule (.*) app/webroot/$1 [L]
RewriteCond %{REQUEST_URI} ^/register
RewriteCond %{REQUEST_URI} ^/login
</IfModule>
Please help , how can I achieve it.
Thanks
You can use these rules:
<IfModule mod_rewrite.c>
RewriteEngine on
# block these URIs
RewriteRule (register|login) - [F,NC]
RewriteRule ^$ app/webroot/ [L]
RewriteRule (.*) app/webroot/$1 [L]
</IfModule>
I want to force SSL for some of my rewritten pages so that they must use SSL.
The urls are:
http://domain.com/signin
http://domain.com/register
I want them to be:
https://domain.com/signin
https://domain.com/register
This is my current .htaccess:
RewriteEngine on
RewriteRule ^signin$ index.php?&action=showLogin [QSA,L,NC]
RewriteRule ^register$ index.php?&action=showRegister [QSA,L,NC]
I have tried the following but it was not successful:
RewriteEngine on
RewriteRule ^signin$ index.php?&action=showLogin [QSA,L,NC]
RewriteRule ^register$ index.php?&action=showRegister [QSA,L,NC]
RewriteCond %{SERVER_PORT} !443
RewriteCond %{REQUEST_URI} ^/(signin|register)
RewriteRule (.*) https://domain.com/$1 [R]
You need redirect to https before internal rewrites.
Use this code:
RewriteEngine on
RewriteCond %{HTTPS} off
RewriteRule ^(signin|register)/?$ https://%{HTTP_HOST}%{REQUEST_URI} [R=301,L,NC]
RewriteCond %{HTTPS} on
RewriteRule !^(signin|register)/? http://%{HTTP_HOST}%{REQUEST_URI} [R=301,L,NC]
RewriteRule ^signin$ index.php?&action=showLogin [QSA,L,NC]
RewriteRule ^register$ index.php?&action=showRegister [QSA,L,NC]
http://www.besthostratings.com/articles/force-ssl-htaccess.html
Sometimes you may need to make sure that the user is browsing your site over securte connection. An easy to way to always redirect the user to secure connection (https://) can be accomplished with a .htaccess file containing the following lines:
RewriteEngine On
RewriteCond %{SERVER_PORT} 80
RewriteRule ^(.*)$ https://www.example.com/$1 [R,L]
Please, note that the .htaccess should be located in the web site main folder.
In case you wish to force HTTPS for a particular folder you can use:
RewriteEngine On
RewriteCond %{SERVER_PORT} 80
RewriteCond %{REQUEST_URI} somefolder
RewriteRule ^(.*)$ https://www.domain.com/somefolder/$1 [R,L]
The .htaccess file should be placed in the folder where you need to force HTTPS.
I have the .htaccess in the main folder (/public_html) with the following lines in it. These are for an application i have installed on my domain.
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteRule ^$ app/webroot/ [L]
RewriteRule (.*) app/webroot/$1 [L]
</IfModule>
It seems like this rule makes every sub-folders inaccessible. For example i have a sub folder called /public_htm/public. I want this sub-folder and all of it's contents to be accessible to public. If i put a .htaccess file in this subfolder, what lines it needs to have to give access to it's content?
Replace your .htaccess with this code:
Options +FollowSymLinks -MultiViews
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteRule ^$ app/webroot/ [L]
# If the request is not for a valid directory
RewriteCond %{REQUEST_FILENAME} !-d
# If the request is not for a valid file
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.+)$ app/webroot/$1 [L]
</IfModule>
I usually use this htaccess file to remove index.php from my URLs in ExpressionEngine
AddType video/ogg .ogv
AddType video/mp4 .mp4
AddType video/webm .webm
AcceptPathInfo On
Options -Indexes
<IfModule mod_rewrite.c>
RewriteEngine On
Options +FollowSymLinks
# Looks for files and directories that do not exist
# and provide the segments to the index.php file
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond $1 !^/index.php
RewriteCond $1 !.(css|js|png|jpe?g|gif|ico)$ [NC]
RewriteRule ^(.*)$ index.php/$1 [L]
</IfModule>
While that works great, before we move this site into production, we're directing all traffic to the given url to another via this htaccess file
RewriteEngine On
RewriteBase /
RewriteCond %{REMOTE_ADDR} !^127\.0\.0\.1
RewriteRule ^(.*)$ http://www.anotherdomain.com/ [R=301,NC]
My own ip address is replacing the localhost call so that I can access the site.
Basically what I'm looking for is a combination of these 2 that will remove index.php from my URLs for me but still redirect everyone else.
Thanks,
Steven
Found that this works great:
RewriteEngine on
# If your IP address matches any of these - then dont re-write
RewriteCond %{REMOTE_ADDR} !^127\.0\.0\.1
RewriteRule ^(.*)$ http://www.anothersite.com/ [R=302,L]
# do not rewrite links to the assets and theme files
RewriteCond $1 !^(assets|themes|images)
# do not rewrite for php files in the document root, robots.txt etc
RewriteCond $1 !^([^\..]+\.php|robots\.txt|crossdomain\.xml)
# but rewrite everything else
RewriteRule ^(.*)$ index.php/$1 [L]