I have recently detected through https://httpstatus.io/ that our .htaccess file while working is causing a double redirect where a single redirect should only be necessary. We are redirecting pages from our old website http://www.gaconsulting.co.kr to our new website which is in a subdirectory at http://www.gaconsulting.co.kr/au/
I would greatly appreciate any advice anyone can provide into how to modify the existing .htaccess to minimize it to a single redirect.
The .htaccess contents are below:
<IfModule mod_substitute.c>
SubstituteMaxLineLength 10M
</IfModule>
# BEGIN WordPress
RewriteEngine On
RewriteCond %{REQUEST_URI} !^/admin/?$
RewriteCond %{REQUEST_URI} !^/css/?$
RewriteCond %{REQUEST_URI} !^/cssmenu/?$
RewriteCond %{REQUEST_URI} !^/easybox/?$
RewriteCond %{REQUEST_URI} !^/etc/?$
RewriteCond %{REQUEST_URI} !^/fck/?$
RewriteCond %{REQUEST_URI} !^/greybox/?$
RewriteCond %{REQUEST_URI} !^/images/?$
RewriteCond %{REQUEST_URI} !^/inc/?$
RewriteCond %{REQUEST_URI} !^/includes/?$
RewriteCond %{REQUEST_URI} !^/jmenucss/?$
RewriteCond %{REQUEST_URI} !^/js/?$
RewriteCond %{REQUEST_URI} !^/lib/?$
RewriteCond %{REQUEST_URI} !^/mail/?$
RewriteCond %{REQUEST_URI} !^/member/?$
RewriteCond %{REQUEST_URI} !^/menujs/?$
RewriteCond %{REQUEST_URI} !^/myform/?$
RewriteCond %{REQUEST_URI} !^/popeye_css/?$
RewriteCond %{REQUEST_URI} !^/popeye_lib/?$
RewriteCond %{REQUEST_URI} !^/Scripts/?$
RewriteCond %{REQUEST_URI} !^/style/?$
RewriteCond %{REQUEST_URI} ^/$
RewriteRule (.*) http://www.gaconsulting.co.kr/au/ [R=301,L]
# Disable the server signature
ServerSignature Off
That rule will never redirect, since all RewriteConds need to match. Something else on your server is causing the double redirect.
Related
I'm currently using:
RewriteEngine on
RewriteCond %{REQUEST_URI} !^/folder/.*
RewriteCond %{REQUEST_URI} !^/folder$
RewriteRule .* https://www.newdomain.com/ [R=301,L]
Which works great at redirecting the "folder" to the "newdomain," including the files within that folder, however, the subfolders within that folder still redirect.
I've tried:
RewriteEngine on
RewriteCond %{REQUEST_URI} !^/folder/.*
RewriteCond %{REQUEST_URI} !^/folder$
RewriteCond %{REQUEST_URI} !^/folder/subfolder/.*
RewriteCond %{REQUEST_URI} !^/folder/subfolder$
RewriteRule .* https://www.newdomain.com/ [R=301,L]
As well as:
RewriteEngine on
RewriteCond %{REQUEST_URI} !^/folder/.*
RewriteCond %{REQUEST_URI} !^/folder$
RewriteCond %{REQUEST_URI} !^/subfolder/.*
RewriteCond %{REQUEST_URI} !^/subfolder$
RewriteRule .* https://www.newdomain.com/ [R=301,L]
with no luck.
Any suggestions?
You can use the following
RewriteEngine On
RewriteCond %{REQUEST_URI} !^/subfolder.*/$ [NC]
RewriteRule .* https://www.newdomain.com/ [R=301,L]
Make sure to clear your browser cache before testing this.
My primary domain on my webhosting I am having point to a subdirectory within public_html via htaccess like so:
RewriteCond %{THE_REQUEST} ^GET\ /apt/
RewriteCond %{HTTP_HOST} ^(www\.)?mysite.com$
RewriteRule ^apt/(.*) /$1 [L,R=301]
RewriteCond %{HTTP_HOST} ^(www\.)?mysite.com$
RewriteRule !^apt/ apt%{REQUEST_URI} [L]
However, within that subdirectory, all URLs include the subdirectory (which is the domain). So it's domain.com/domain.com/page. Locally I use AMPPS and so the URLs are localhost/domain.com/page. Something I should fix...
How do I remove the subdirectory from URL paths? Do I do so in the htaccess within the subdirectory? Thanks.
UPDATE: Now after plenty of messing around, the root htaccess has:
RewriteEngine on
RewriteBase /
RewriteCond %{HTTP_HOST} ^(www\.)?my-web.agency$
RewriteRule !^my-web.agency/ my-web.agency/%{REQUEST_URI} [L,NC]
URLs work with and without the subdirectory in URL; however I want to disallow the subdirectory from the URI.
Also every link auto-generated by ProcessWire includes the subdir in URI.
Inside the subdir my-web.agency is a ProcessWire install (think WordPress for this case) with the following:
<IfModule mod_rewrite.c>
RewriteEngine On
AddDefaultCharset UTF-8
RewriteRule "(^|/)\.(?!well-known)" - [F]
RewriteCond %{REQUEST_URI} !(^|/)site-[^/]+/install/[^/]+\.(jpg|jpeg|png|gif)$
RewriteCond %{REQUEST_URI} (^|/)\.htaccess$ [NC,OR]
RewriteCond %{REQUEST_URI} (^|/)(site|site-[^/]+)/assets/(cache|logs|backups|sessions|config|install|tmp)($|/.*$) [OR]
RewriteCond %{REQUEST_URI} (^|/)(site|site-[^/]+)/install($|/.*$) [OR]
RewriteCond %{REQUEST_URI} (^|/)(site|site-[^/]+)/assets.*/-.+/.* [OR]
RewriteCond %{REQUEST_URI} (^|/)(wire|site|site-[^/]+)/(config|index\.config|config-dev)\.php$ [OR]
RewriteCond %{REQUEST_URI} (^|/)(wire|site|site-[^/]+)/templates-admin($|/|/.*\.(php|html?|tpl|inc))$ [OR]
RewriteCond %{REQUEST_URI} (^|/)(site|site-[^/]+)/templates($|/|/.*\.(php|html?|tpl|inc))$ [OR]
RewriteCond %{REQUEST_URI} (^|/)(site|site-[^/]+)/assets($|/|/.*\.php)$ [OR]
RewriteCond %{REQUEST_URI} (^|/)wire/(core|modules)/.*\.(php|inc|tpl|module|info\.json)$ [OR]
RewriteCond %{REQUEST_URI} (^|/)(site|site-[^/]+)/modules/.*\.(php|inc|tpl|module|info\.json)$ [OR]
RewriteCond %{REQUEST_URI} (^|/)(COPYRIGHT|INSTALL|README|htaccess)\.(txt|md|textile)$ [OR]
RewriteCond %{REQUEST_URI} (^|/)site-default/
RewriteRule ^.*$ - [F,L]
RewriteCond %{REQUEST_URI} "^/~?[-_.a-zA-Z0-9/]*$"
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !(favicon\.ico|robots\.txt)
RewriteRule ^(.*)$ index.php?it=$1 [L,QSA]
How do I remove the subdirectory from the URL? Please?
I am trying to setup a codeigniter app to force HTTPS across all pages except one. However, I cannot get the rules to only redirect if the user is not on the page in question.
The page that should be excluded has the following URL's:
http://mydomain.com/kpi/reports/67
http://mydomain.com/kpi/reports/67/overview/2013-02-01/2013-02-28
http://mydomain.com/index.php?/kpi/reports/67
http://mydomain.com/index.php?/kpi/reports/67/overview/2013-02-01/2013-02-28
The number 67 and the dates can all change in the URL's above hence the user of regular expressions below.
I have tested the regular expressions and they seem to match the URL's fine. However, the htaccess just seems to redirect it to https:// anyway.
My .htaccess file is as follows...
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
#Disallow access to system dir
RewriteCond %{REQUEST_URI} ^system.*
RewriteRule ^(.*)$ /index.php?/$1 [L]
#Disallow access to application dir
RewriteCond %{REQUEST_URI} ^application.*
RewriteRule ^(.*)$ /index.php?/$1 [L]
#Force https when not on overview report
RewriteCond %{HTTPS} off
RewriteCond %{REQUEST_URI} !^/index\.php\?/kpi/reports/?([0-9]+)$
RewriteCond %{REQUEST_URI} !^/index\.php\?/kpi/reports/?([0-9]+)/overview/?([0-9]+)-?([0-9]+)-?([0-9]+)/?([0-9]+)-?([0-9]+)-?([0-9]+)$
RewriteCond %{REQUEST_URI} !^/kpi/reports/?([0-9]+)$
RewriteCond %{REQUEST_URI} !^/kpi/reports/?([0-9]+)/overview/?([0-9]+)-?([0-9]+)-?([0-9]+)/?([0-9]+)-?([0-9]+)-?([0-9]+)$
RewriteRule ^(.*)$ https://%{SERVER_NAME}%{REQUEST_URI} [R=302,L]
#If not a valid file, redirect request through index.php
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php?/$1 [L]
</IfModule>
Any help would be greatly appreciated!
Maybe this will do what you need:
#Force https when not on overview report
RewriteCond %{HTTPS} off
RewriteCond %{QUERY_STRING} !kpi/reports/[0-9]+/?$ [NC]
RewriteCond %{QUERY_STRING} !kpi/reports/[0-9]+/overview/[^/]+/[^/]+/? [NC]
RewriteCond %{REQUEST_URI} !kpi/reports/[0-9]+/?$ [NC]
RewriteCond %{REQUEST_URI} !kpi/reports/[0-9]+/overview/[^/]+/[^/]+/? [NC]
RewriteRule ^(.*)$ https://%{SERVER_NAME}%{REQUEST_URI} [R=302,L]
#If not a valid file, redirect request through index.php
Replace all lines between the comments.
I have a problem with an redirect exception.
All the files in root were redirected to /
I want create a exception for the sitemap.xml.
My htaccess :
RewriteCond %{HTTP_HOST} ^www.website.com$
RewriteCond %{REQUEST_URI} ^/$
RewriteCond %{REQUEST_URI} !sitemap.xml$
RewriteRule ^(.*)$ site/web/website/index.php [L]
RewriteCond %{HTTP_HOST} ^www.website.com$
RewriteCond %{REQUEST_URI} ^/site/web/website/$
RewriteCond %{REQUEST_URI} !sitemap.xml$
RewriteRule .* http://www.website.com/ [R=301,L]
RewriteCond %{HTTP_HOST} ^website.com$
RewriteCond %{REQUEST_URI} ^/site/web/website/$
RewriteRule .* http://www.website.com/ [R=301,L]
But does not work :(.
Many thanks
I have this line in my htaccess file: RewriteRule (.*) index.php
This catches all requests being sent to my site domain.com
Now i have created a subdomain blog.domain.com and i am getting an Internal server error. How can i add blog.domain.com as an exception in htaccess.
This is my whole htaccess file:
Options +FollowSymLinks
RewriteEngine On
RewriteCond %{REQUEST_URI} .*/http-bind
RewriteRule (.*) /http-bind [L]
RewriteCond %{REQUEST_URI} !^/index.php
RewriteCond %{REQUEST_URI} !/ow_updates/index.php
RewriteCond %{REQUEST_URI} !/ow_updates/
RewriteCond %{REQUEST_URI} (/|\.php|\.html|\.htm|\.feed|\.raw|/[^.]*)$ [NC]
RewriteCond %{REQUEST_URI} !/ow_updates/
RewriteCond %{REQUEST_URI} !/google3ce18567a119af4.html
RewriteRule (.*) index.php
Add the following line to the top of your RewriteCond block.
RewriteCond %{HTTP_HOST} !^blog\.domain\.com
RewriteCond %{REQUEST_URI} !^/index.php
RewriteCond %{REQUEST_URI} !/ow_updates/index.php
RewriteCond %{REQUEST_URI} !/ow_updates/
RewriteCond %{REQUEST_URI} (/|\.php|\.html|\.htm|\.feed|\.raw|/[^.]*)$ [NC]
RewriteCond %{REQUEST_URI} !/ow_updates/
RewriteCond %{REQUEST_URI} !/google3ce18567a119af4.html
This will only pass when the request is not for blog.domain.com and meets all of your current conditions.
As a side, I would encourage you to do something more like the following as opposed to your specific file checks.
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
This ensures that the request is not an existing file or directory. It's easier to maintain than whitelisting specific resources (e.g. google3ce18567a119af4.html, /ow_updates/, etc).