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';
Related
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>
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>
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]
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]
I use CodeIgniter and I want to set URL by htaccess. I have tried many ways but have not succeeded yet.
My folder structure :
--application
----corntrollers
-------public
----------home.php
----------log
-------------- login.php
-------admin
----views
-------public
----------home.tpl
----------log
-------------- login.tpl
--system
--mysite
I want to set URL to rewrite :
http://localhost/mysite/index.php/log/login
=>
http://localhost/mysite/log-in
How can I do that ?
Enable url rewriting module of Apache2:
a2enmod rewrite
Change /config/config.php
$config['index_page'] = "index.php";
to
$config['index_page'] = "";
As well
$config['uri_protocol'] = 'AUTO';
to
$config['uri_protocol'] = 'REQUEST_URI';
The correct way of .htaccess is:
#AddHandler application/x-httpd-php5 .php
<IfModule mod_rewrite.c>
RewriteEngine On
#RewriteBase /
#Removes access to the system folder by users.
#Additionally this will allow you to create a System.php controller,
#previously this would not have been possible.
#'system' can be replaced if you have renamed your system folder.
RewriteCond %{REQUEST_URI} ^system.*
RewriteRule ^(.*)$ index.php?/$1 [L]
#Checks to see if the user is attempting to access a valid file,
#such as an image or css document, if this isn't true it sends the
#request to index.php
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php?/$1 [L]
</IfModule>
<IfModule !mod_rewrite.c>
# If we don't have mod_rewrite installed, all 404's
# can be sent to index.php, and everything works as normal.
# Submitted by: ElliotHaughin
ErrorDocument 404 index.php
</IfModule>
php_flag short_open_tag on
<FilesMatch "\.(php)$">
FileETag None
<IfModule mod_headers.c>
Header unset ETag
Header set Cache-Control "max-age=0, no-cache, no-store, must-revalidate"
Header set Pragma "no-cache"
Header set Expires "Wed, 11 Jan 1984 05:00:00 GMT"
</IfModule>
</FilesMatch>
Restar Apache2 Service:
sudo systemctl restart apache2.service
Hope that helps.
First of all make sure url rewriting is enabled and then create .htaccess file with code below.
DirectoryIndex index.php
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ ./index.php/$1 [L,QSA]
Then in /config/config.php
/*
|--------------------------------------------------------------------------
| Index File
|--------------------------------------------------------------------------
|
| Typically this will be your index.php file, unless you've renamed it to
| something else. If you are using mod_rewrite to remove the page set this
| variable so that it is blank.
|
*/
$config['index_page'] = 'index.php';
change
$config['index_page']
to
$config['index_page'] = '';
Next in
/config/routes.php
$route['log-in'] = "log/log-in";