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).
Related
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.
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.
Some lines of my htaccess file will be look like as follows
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI} !\.css$
RewriteCond %{REQUEST_URI} !\.js$
RewriteCond %{REQUEST_URI} !\.images$
RewriteCond %{REQUEST_URI} ^/(.*)$
RewriteCond %{REQUEST_URI} !(\.jpg|\.gif|\.png)$ [NC]
RewriteRule ^(.*)$ user/$1 [L,QSA]
But when I go for a invalid url, so for mydomain.com/blablabla ,it's giving Internal Server Error. Is anything wrong with my .htaccess
Try adding these conditions right after RewriteCond %{REQUEST_URI} ^/(.*)$
RewriteCond %{DOCUMENT_ROOT}/user/%1 -f [OR]
RewriteCond %{DOCUMENT_ROOT}/user/%1 -d
This checks if the rewritten URI would exist, if it doesn't, it won't do the rewrite, which is causing an internal loop if the URI doesn't exist.
I am trying to point a subfolder on my site as a subdomain. for example, i want to turn www.domain.com/test to test.domain.com. I already have some rewrites in htaccess done by developers that we used earlier in the site building process, and I'd like to be able to add this line without interfering with those.
I've tried dozens of answers to this issue i found across the net, but none of them seemed to work and i'm not sure if it's due to my lack of knowledge of this language or if there's a conflict with something else.
The latest lines I tried are:
RewriteCond %{HTTP_HOST} !^www.domain.tv
RewriteCond %{HTTP_HOST} ([^.]+).domain.tv
RewriteRule ^(.*)$ /var/www/www.domain.tv/test%1
This is my current htaccess file:
Options +FollowSymLinks
RewriteEngine On
RewriteBase /
#RewriteCond %{HTTP_HOST} !www\.domain\.tv$ [NC]
#RewriteCond %{HTTP_HOST} ^(.+)\.domain\.tv$ [NC]
#RewriteRule .* index.php?option=com_contushdvideoshare&view=player&Itemid=33 [L]
RewriteCond %{REQUEST_URI} ^/album\/t\/([a-zA-Z0-9]+) [NC]
RewriteRule ^album/t/(.*) index.php?option=com_usermenu&task=directdownload&id=$1&type=one$
RewriteCond %{REQUEST_URI} ^/album\/([a-zA-Z0-9]+) [NC]
RewriteRule ^album/(.*) index.php?option=com_usermenu&task=directdownload&id=$1 [L]
RewriteCond %{QUERY_STRING} mosConfig_[a-zA-Z_]{1,21}(=|\%3D) [OR]
RewriteCond %{QUERY_STRING} base64_encode[^(]*\([^)]*\) [OR]
RewriteCond %{QUERY_STRING} (<|%3C)([^s]*s)+cript.*(>|%3E) [NC,OR]
RewriteCond %{QUERY_STRING} GLOBALS(=|\[|\%[0-9A-Z]{0,2}) [OR]
RewriteCond %{QUERY_STRING} _REQUEST(=|\[|\%[0-9A-Z]{0,2})
RewriteRule .* index.php [F]
#RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}]
RewriteCond %{REQUEST_URI} !^/index\.php
RewriteCond %{REQUEST_URI} (/[^.]*|\.(php|html?|feed|pdf|raw))$ [NC]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule .* index.php [L]
Can anyone help me here?
Try:
RewriteCond %{HTTP_HOST} !^www.domain.tv [NC]
RewriteCond %{HTTP_HOST} ([^\.]+).domain.tv [NC]
RewriteRule ^(.*)$ %1/$1 [L]
Subdomains aren't so easy to set up. You will need to configure your server before. More informations here : Create subdomains on the fly with .htaccess (PHP)