.htaccess throws Internal server error for subdomain - .htaccess

I have created a subdomain comments.yoursite.com to deploy a commenting plugin for the main site www.yoursite.com. Whenever I point my browser to the comments.yoursite.com/app/install.php or comments.yoursite.com it throws Internal error
My .htaccess file:
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteRule ^(.*)$ public/$1 [L]
</IfModule>
<ifModule mod_gzip.c>
mod_gzip_on Yes
mod_gzip_dechunk Yes
mod_gzip_item_include file .(html?|txt|css|js|php|pl)$
mod_gzip_item_include handler ^cgi-script$
mod_gzip_item_include mime ^text/.*
mod_gzip_item_include mime ^application/x-javascript.*
mod_gzip_item_exclude mime ^image/.*
mod_gzip_item_exclude rspheader ^Content-Encoding:.*gzip.*
</ifModule>
File structure:
Main site: home/yoursite/public_html/public
Comments plugin: home/yoursite/comments
When I delete the htaccess file the comments plugin works but the main site shows Not found. Cant get them both working at the same time :(
I am using Laravel.
Please help O_o

You need two distinct RewriteCondition(s) and rules for the two use cases - try something like this:
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{HTTP_HOST} ^comments.yoursite.com
RewriteRule ^(.*)$ http://yoursite.com/comments/$1 [NC,L]
RewriteCond %{HTTP_HOST} ^www$
RewriteRule ^(.*)$ public/$1 [NC,L]
</IfModule>

Related

Specific URL redirect to home page

I am creating a small script in Codeigniter. I want to integrate OneSignal for push notification. But the problem is, below URL redirect to the home page.
https://example.com/OneSignalSDKWorker.js?appId=1234567890xxxxx-xxxxx-xxx
Here is my full .htaccess code
DirectoryIndex index.php
RewriteEngine on
RewriteCond %{HTTPS} off
RewriteCond %{HTTP:X-Forwarded-Proto} !https
RewriteRule ^(.*)$ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
RewriteCond $1 !^(index\.php|images|css|js|robots\.txt|favicon\.ico)
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ ./index.php/$1 [L,QSA]
<IfModule mod_gzip.c>
mod_gzip_on Yes
mod_gzip_dechunk Yes
mod_gzip_item_include file \.(html?|txt|css|js|php|pl|jpg|png|gif)$
mod_gzip_item_include handler ^cgi-script$
mod_gzip_item_include mime ^text/.*
mod_gzip_item_include mime ^application/x-javascript.*
mod_gzip_item_exclude mime ^image/.*
mod_gzip_item_exclude rspheader ^Content-Encoding:.*gzip.*
</IfModule>
And here is my basic Codeigniter route
<?php
defined('BASEPATH') OR exit('No direct script access allowed');
$route['default_controller'] = 'controller';
$route['404_override'] = '';
$route['translate_uri_dashes'] = FALSE;
//first route
$route['(:any)/(:any)'] = 'controller/method/$1/$2';
//second route
$route['(:any)'] = 'controller/method/$1';
here my controller can take one or two arguments. If I pass only first arguments (i.e send route) and check if it's not present in my database it will redirect to the home page. Similarly for the first route check both are not present it will redirect to home page.
But the problem is when I try to access this https://example.com/OneSignalSDKWorker.js?appId=1234567890xxxxx-xxxxx-xxx it will redirect to home page.
So my question is how to exclude it from redirect rule?
You can change your line:
RewriteCond $1 !^(index\.php|images|css|js|robots\.txt|favicon\.ico)
to
RewriteCond $1 !^(index\.php|images|css|js|robots\.txt|favicon\.ico|OneSignalSDKWorker\.js)
I'm not sure, but give this a try
Add this line before first route
$route['OneSignalSDKWorker.js(:any)'] = 'OneSignalSDKWorker.js$1';

htaccess redirect issue due to php version upgradation

I have uploaded the PHP version from 5.3 to 5.5 for my website but it redirects to coming-soon page which I set for 401, 403, 500.
It works on old PHP version(5.3)
http://www.techmodi.com/demo/jaspee/services/getCMS?id=1
but It does not work for upgraded version i.e. 5.5
http://apis.jaspee.com/services/getCMS?id=1
I have also tried with AddHandler application/x-httpd-php55 .php but id downloads the file instead of executing.
can you please suggest the solution for the same?
root folder .htaccess file
Options -MultiViews
<IfModule mod_rewrite.c>
RewriteEngine on
# Remove below Hash comment when your porject is going live (This is for PHP 5 support)
#AddHandler application/x-httpd-php5 .php
Options -Indexes
#Base navigational rules
DirectoryIndex index.php
RewriteRule ^index.php|index.html|default.php|default.html$ index.php [QSA,L]
#RewriteRule ^index.php$ controller/home/home.php [QSA,L]
#Admin interface URL
RewriteRule ^admin/{0,1}$ admin/index.php [QSA,L]
#User interface URLs
RewriteRule ^aboutus[/]{0,1}$ controller/cms/cms.php?id1=1
RewriteRule ^([a-zA-Z0-9_=-]+)/([a-zA-Z0-9_=-]+)/{0,1}$ panel.php?id1=$2
# Folder name($1) / File name($1) (Use this when your folder name and file name is same)
RewriteRule ^([a-zA-Z0-9_=-]+)/{0,1}$ controller/$1/$1.php
#Folder name($1) / File name($2)
RewriteRule ^([a-zA-Z0-9_=-]+)/([a-zA-Z0-9_=-]+)/{0,1}$ controller/$1/$2.php
#Folder name($1) / First Parameter($2) / File name($3)
RewriteRule ^([a-zA-Z0-9_=-]+)/([a-zA-Z0-9_=-]+)/([a-zA-Z0-9_=-]+)/{0,1}$ controller/$1/$3.php?id1=$2
#Folder name($1) / First Parameter($2) / Second Parameter($3) / File name($4)
RewriteRule ^([a-zA-Z0-9_=-]+)/([a-zA-Z0-9_=-]+)/([a-zA-Z0-9_=-]+)/([a-zA-Z0-9_=-]+)/{0,1}$ controller/$1/$4.php?id1=$2&id2=$3
#Folder name($1) / First Parameter($2) / Second Parameter($3) / Third Parameter($4) / File name($5)
RewriteRule ^([a-zA-Z0-9_=-]+)/([a-zA-Z0-9_=-]+)/([a-zA-Z0-9_=-]+)/([a-zA-Z0-9_=-]+)/([a-zA-Z0-9_=-]+)/{0,1}$ controller/$1/$5.php?id1=$2&id2=$3&id3=$4
#Folder name($1) / First Parameter($2) / Second Parameter($3) / Third Parameter($4) / Fourth Parameter($5) / File name($6)
RewriteRule ^([a-zA-Z0-9_=-]+)/([a-zA-Z0-9_=-]+)/([a-zA-Z0-9_=-]+)/([a-zA-Z0-9_=-]+)/([a-zA-Z0-9_=-]+)/([a-zA-Z0-9_=-]+)/{0,1}$ controller/$1/$6.php?id1=$2&id2=$3&id3=$4&id4=$5
#Folder name($1) / File name($2)
RewriteRule ^([a-zA-Z0-9_=-]+)/([a-zA-Z0-9_=-]+).html controller/$1/$2.php
# Module htaccess end
RewriteCond %{REQUEST_FILENAME} -f [OR]
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule .+ - [L]
# Page not found
ErrorDocument 400 http://apis.jaspee.com/comingsoon.php
ErrorDocument 401 http://apis.jaspee.com/comingsoon.php
ErrorDocument 403 http://apis.jaspee.com/comingsoon.php
ErrorDocument 404 http://apis.jaspee.com/404.php
ErrorDocument 500 http://apis.jaspee.com/comingsoon.php
</IfModule>
<ifModule mod_gzip.c>
mod_gzip_on Yes
mod_gzip_dechunk Yes
mod_gzip_item_include file .(html?|txt|css|js|php|pl)$
mod_gzip_item_include handler ^cgi-script$
mod_gzip_item_include mime ^text/.*
mod_gzip_item_include mime ^application/x-javascript.*
mod_gzip_item_include mime ^images/.*
mod_gzip_item_exclude rspheader ^Content-Encoding:.*gzip.*
</ifModule>
# Check String ([A-Za-z]+)
# Check Number ([0-9]+)
# MIX ([a-zA-Z0-9_-]+)
web service .htaccess folder
<IfModule mod_rewrite.c>
RewriteEngine On
# RewriteBase /jspee
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-s
RewriteRule ^(.*)$ srvcRest.php?rqst=$1 [QSA,NC,L]
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^(.*)$ srvcRest.php [QSA,NC,L]
RewriteCond %{REQUEST_FILENAME} -s
RewriteRule ^(.*)$ srvcRest.php [QSA,NC,L]
</IfModule>
<Limit GET POST PUT DELETE>
Allow from all
</Limit>

htaccess rule fails sometimes but not always

i have the following rule to my htaccess
RewriteRule ^(el|en)/(.*).html/?$ article.php?lang=$1&url=$2 [L,NC,QSA]
When a user goes to
www.mydomain.com/en/this-is-an-article.html
the rule forward to article.php and show the page.
The problem is that sometimes the rules fails and instead of go to
www.mydomain.com/en/this-is-an-article.html
its go to
www.mydomain.com/article.php
and the page is not render because the passing parameters are not send and can not handle it
If you make another click to see the page the page render as expected.
Its the first time i see something like that.
full htaccess code
RewriteEngine on
Options -Indexes
AddDefaultCharset UTF-8
IndexIgnore .htaccess */.??* *~ *# */HEADER* */README* */_vti*
<IfModule mod_security.c>
SecFilterEngine Off
SecFilterScanPOST Off
</IfModule>
<Limit GET POST>
order deny,allow
deny from all
allow from all
</Limit>
<Limit PUT DELETE>
order deny,allow
deny from all
</Limit>
# WEEK
<FilesMatch "\.(pdf|swf|js|css|jpg|png|gif|JPG)$">
Header set Cache-Control "max-age=604800"
</FilesMatch>
<ifModule mod_gzip.c>
mod_gzip_on Yes
mod_gzip_dechunk Yes
mod_gzip_item_include file \.(html?|txt|css|js|php|pl|ttf|woff)$
mod_gzip_item_include handler ^cgi-script$
mod_gzip_item_include mime ^text/.*
mod_gzip_item_include mime ^application/x-javascript.*
mod_gzip_item_exclude mime ^image/.*
mod_gzip_item_exclude rspheader ^Content-Encoding:.*gzip.*
</ifModule>
#fcp.php
RewriteRule ^(el|en)/fcp.php?$ fcp.php?lang=$1 [L,NC,QSA]
#tuner.php
RewriteRule ^(el|en)/index-b/(.*).html/?$ index-b.php?lang=$1&url=$2 [L,NC,QSA]
RewriteRule ^(el|en)/catalog-b/(.*).html/?$ catalog-b.php?lang=$1&url=$2 [L,NC,QSA]
#product.php
RewriteRule ^(el|en)/product/(.*).html/?$ product.php?lang=$1&url=$2 [L,NC,QSA]
#article.php
RewriteRule ^(el|en)/(.*).html/?$ article.php?lang=$1&url=$2 [L,NC,QSA]
#controller.php
RewriteRule ^(el|en)/(.*)/p/([^.]+)?$ controller.php?lang=$1&url=$2&p=$3 [L,NC,QSA]
RewriteRule ^(el|en)/(.*)/?$ controller.php?lang=$1&url=$2 [L,NC,QSA]
#index.php
RewriteRule ^(el|en)?$ index.php?lang=$1 [L,NC,QSA]
Can anyone help
Try placing this code at top of your .htaccess:
# disable MultiViews as it conflicts with mod_rewrite
Options +FollowSymLinks -MultiViews
RewriteEngine on
# skip further rewrites if rewrite has already happened OR else
# if request is for a valid file/directory
RewriteCond %{ENV:REDIRECT_STATUS} 200 [OR]
RewriteCond %{REQUEST_FILENAME} -d [OR]
RewriteCond %{REQUEST_FILENAME} -f [OR]
RewriteCond %{REQUEST_FILENAME} -l
RewriteRule ^ - [L]

new htaccess .html rule causing redirection

Please can someone help, we are having problems with our htaccess.
We have created a rule sending everything ending .html (our product pages) to our details.cfm page. However after creating this rule our admin area subdirectory is redirecting to the index page.
Have we set this up properly? I think we have an error here
# Rewrite rules for non www entrances
RewriteEngine On
RewriteBase /
RewriteCond %{HTTP_HOST} !^www.ourdomain.co.uk$ [NC]
RewriteRule ^(.*)$ http://www.ourdomain.co.uk/$1 [L,R=301]
# Rewrite rules - new rule
RewriteRule (.*).html$ /Details.cfm?ProductUrl=$1 [NC]
# Rewrite rules - current rules
RewriteRule (.*)-sku-(.*)$ /Details.cfm?Name=$1&ProductCode=$2 [NC]
RewriteRule (.*)-shop-(.*)$ /Results.cfm?bname=$1&Brand=$2 [NC]
RewriteRule (.*)-cat1-(.*)$ /SubCat.cfm?catname=$1&category=$2 [NC]
RewriteRule (.*)-cat2-(.*)$ /SubSubCat.cfm?secondcatname=$1&secondary=$2 [NC]
RewriteRule (.*)-cat3-(.*)$ /Results.cfm?thirdcatname=$1&third=$2 [NC]
RewriteRule (.*)-shop$ /ResultsShop.cfm?bname=$1 [NC]
# Rewrite rule - If no extension specified use cfm
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}\.cfm -f
RewriteRule ^(.*)$ $1.cfm
# Rwerite rule - 404 redirect rule
ErrorDocument 404 /cferror.cfm
# Gzip rule to speed up website with image caching
<ifModule mod_gzip.c>
mod_gzip_on Yes
mod_gzip_dechunk Yes
mod_gzip_item_include file \.(html?|txt|css|js|php|pl)$
mod_gzip_item_include handler ^cgi-script$
mod_gzip_item_include mime ^text/.*
mod_gzip_item_include mime ^application/x-javascript.*
mod_gzip_item_exclude mime ^image/.*
mod_gzip_item_exclude rspheader ^Content-Encoding:.*gzip.*
</ifModule>
We also have an htaccess file in the directory which checks for a htpasswd
AuthType Basic
AuthName "Admin"
AuthUserFile "/home/ourdomain/.htpasswds/public_html/v3/passwd"
require valid-user
RewriteEngine On
# This will enable the Rewrite capabilities
RewriteCond %{HTTPS} !=on
# This checks to make sure the connection is not already HTTPS
RewriteRule ^/?v3/(.*) https://%{SERVER_NAME}/v3/$1 [R,L]
Thankyou!
Add this rule just below RewriteBase / line:
# skip v3 from rewrite
RewriteRule ^v3(/.*)?$ - [NC,L]

Url mod_rewrite remove consequtive trailing slashes on clean urls

Hello I would like to remove any trailing slashes from my clean urls so far my htaccess has the following code:
#php_flag display_startup_errors on
#php_flag display_errors on
#php_flag html_errors on
RewriteEngine on
<IfModule mod_gzip.c>
mod_gzip_on Yes
mod_gzip_dechunk Yes
mod_gzip_item_include file \.(html?|txt|css|js|php|pl|jpg|png|gif)$
mod_gzip_item_include handler ^cgi-script$
mod_gzip_item_include mime ^text/.*
mod_gzip_item_include mime ^application/x-javascript.*
mod_gzip_item_exclude mime ^image/.*
mod_gzip_item_exclude rspheader ^Content-Encoding:.*gzip.*
</IfModule>
Options -Indexes
RewriteCond %{REQUEST_FILENAME} !-f
#RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^([^/]*)(.*)$ /index.php?page=$1&request=$2
#GAMW TON OHANAH
RedirectMatch 301 ^/component/(.*)$ http://www . evented . gr
ErrorDocument 404 /error.php?e=404
ErrorDocument 400 /error.php?e=400
ErrorDocument 401 /error.php?e=401
ErrorDocument 403 /error.php?e=403
ErrorDocument 405 /error.php?e=405
ErrorDocument 408 /error.php?e=408
ErrorDocument 410 /error.php?e=410
ErrorDocument 411 /error.php?e=411
ErrorDocument 412 /error.php?e=412
ErrorDocument 413 /error.php?e=413
ErrorDocument 414 /error.php?e=414
ErrorDocument 415 /error.php?e=415
ErrorDocument 500 /error.php?e=500
ErrorDocument 501 /error.php?e=501
ErrorDocument 502 /error.php?e=502
ErrorDocument 503 /error.php?e=503
ErrorDocument 506 /error.php?e=506
You may observe the strange behaviour if you like by visiting www . evented . gr
PS. I want consequtive slashes that have nothing in between to be replaced with 0 slash
for example www.domain.com////// to www.domain.com
or www.domain.com/events////// to www.domain.com/events
I have tryed the following but with no luck
RewriteCond %{REQUEST_URI} ^(.*?)(?:/){2,}$
RewriteRule . $1/ [R=301,L]
and
RewriteCond %{REQUEST_URI} ^(.*)//(.*)$
RewriteRule . %1/%2 [R=301,L]
You can't do this with mod_rewrite. By the time your rules get applied, apache has already normalized the URI, all duplicate slashes are removed. If you make a request for:
http://www.evented.gr//////a////////b/////c/////d///////
The URI that mod_rewrite sees is this:
/a/b/c/d/
You'll have to come up with a different solution. The best thing to do is to fix this at the source, don't deploy with URLs that have duplicate slashes in the first place.

Resources