Specific URL redirect to home page

Viewed 112

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?

2 Answers

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