new htaccess .html rule causing redirection - .htaccess

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]

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';

CMS Made Simple .htaccess Redirect for non-WWW

I need some help with a CMS Made Simple website that has pretty URLs enabled.
At the moment I have http://www.example.com/ going to http://example.com/
However If I try and access http://www.example.com/pagename it goes to http://example.com/index.php?page=pagename when it should be going to http://example.com/pagename
Additionally I want to redirect http://example.com/index.php to http://example.com/
I've included the contents of my .htaccess file below:
# Attempt to override some php settings, these settings may be helpful on some hosts if your
# default configuration does not meet CMS's minimum requirements, and your host
# has given your account appropriate permissions
#php_value upload_max_filesize "10M"
#php_value session_save_path "tmp/cache"
#php_flag magic_quotes_gpc Off
#php_flag register_globals Off
#php_flag session.use_trans_sid Off
# (this is important, so uncomment if your host permit)
#Options -Indexes
#ServerSignature Off
#Options +FollowSymLinks
# To prevent E_STRICT problems with PHP 5.3+ you can uncomment the following lines
# Note: These settings should only be enabled for production sites!
#php_flag display_startup_errors 0
#php_flag display_errors 0
#php_flag html_errors 0
#php_value docref_root 0
#php_value docref_ext 0
<IfModule mod_rewrite.c>
RewriteEngine on
#
#Sub-dir e.g: /cmsms
RewriteBase /
# 301 Redirect all requests that don't contain a dot or trailing slash to
# include a trailing slash
# but ignore POST requests.
#RewriteCond %{REQUEST_URI} !/$
#RewriteCond %{REQUEST_URI} !\.
#RewriteCond %{REQUEST_METHOD} !POST$
#RewriteRule ^(.*) %{REQUEST_URI}/ [R=301,L]
# Rewrites urls in the form of /parent/child/
# but only rewrites if the requested URL is not a file or directory
#
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.+)$ index.php?page=$1 [QSA]
#RewriteEngine On
#RewriteCond %{HTTP_HOST} !^www\.
#RewriteRule ^(.*)$ http://www.%{HTTP_HOST}/$1 [R=301,L]
RewriteCond %{HTTP_HOST} ^www.example.com$ [NC]
RewriteRule ^(.*)$ http://example.com/$1 [R=301]
</IfModule>
<IfModule mod_header.c>
# Disable ETags
Header unset ETag
FileEtag None
</IfModule>
<IfModule mod_deflate.c>
# Compress css, plaintext, xml, gif, and images in transport.
AddOutputFilterByType DEFLATE text/css text/plain text/xml image/gif image/jpeg image/png
</IfModule>
<IfModule mod_expires.c>
<FilesMatch "\.(ico|pdf|flv|jpg|jpeg|png|gif|js|css|swf)$">
# Set expires tags on various files... so that the browser wont attempt to reload them.
ExpiresActive On
ExpiresDefault "access plus 1 year"
<IfModule mod_header.c>
# Setting cache control to public allowes proxy servers to cache the items too.
Header set Cache-Control "public"
</IfModule>
</FilesMatch>
</IfModule>
You need to move the www to non-www redirect above the internal index.php rewrite. Additionally, I would recommend adding the L flag to the internal rewrite. This flag is required for the 'www' redirect as well. Lastly, the internal rewrite needs to use (.*) instead of (.+) as the former includes requests to the root, whilst the latter does not.
RewriteCond %{HTTP_HOST} ^www.example.com$ [NC]
RewriteRule ^(.*)$ http://example.com/$1 [R=301,L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php?page=$1 [QSA,L]
Currently, the request is internally re-written to index.php?page=$1, which becomes the new request URI, which is then appended to the next redirect if 'www' is not included. Swapping those two blocks around will solve the issue.
To redirect /index.php to /, place the following redirect above the 'www' redirect shown above.
RewriteRule ^index.php$ / [R=302,L]
To make that redirect permanent and cached by browsers and search engines, change 302 to 301.

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 file adding directories to URL

I have an htaccess file that is supposed to direct the user to a non www URL. Problem is, the site has directories that get added to the end of the URL when clicked on.
For example, subdomain.domain.com becomes subdomain.domain.com/folder/home.html, which is fine, but if the link is clicked again, it becomes subdomain.domain.com/folder/folder/home.html, and so on. Not so good.
Here is the .htaccess file:
RewriteEngine On
RewriteBase /
# Rewrite www.domain.com -> domain.com -- used with SEO Strict URLs plugin
RewriteCond %{HTTP_HOST} .
RewriteCond %{HTTP_HOST} !^subdomain\.domain\.com [NC]
RewriteRule (.*) http://subdomain.domain.com/$1 [R=301,L]
#
# or for the opposite domain.com -> www.domain.com use the following
# DO NOT USE BOTH
#
#RewriteCond %{HTTP_HOST} .
#RewriteCond %{HTTP_HOST} !^www\.sitehere\.com [NC]
#RewriteRule (.*) http://www.sitehere.com/$1 [R=301,L]
# The Friendly URLs part
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php?q=$1 [L,QSA]
# Make sure .htc files are served with the proper MIME type, which is critical
# for XP SP2. Un-comment if your host allows htaccess MIME type overrides.
#AddType text/x-component .htc
<FilesMatch "\.(ttf|otf|eot|woff)$">
<IfModule mod_headers.c>
Header set Access-Control-Allow-Origin "*"
</IfModule>
</FilesMatch>
Any help would be greatly appreciated.
Thanks!
check your base href tag in your templates and the system variable it outputs, I think it's ++site_url [you can check in your template what it actually is]

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]

Resources