Previously working .htaccess in codeigniter 3.1.2 not working after trying prerender.io

275 views Asked by At

I was using the following configuration in .htaccess file:

<IfModule mod_rewrite.c>
  RewriteEngine On
  #RewriteBase /
  RewriteCond %{REQUEST_FILENAME} !-f
  RewriteRule ^ index.php [QSA,L]
</IfModule>

It was working fine and the home page was displayed as soon as I entered www.my-site.com.

Then I tried to implement prerender.io in codeigniter using the .htaccess file provided in this link: https://gist.github.com/thoop/8072354. The new .htaccess file is as follows:

<IfModule mod_headers.c>
  RequestHeader set X-Prerender-Token "MY_TOKEN"
</IfModule>

<IfModule mod_rewrite.c>
  RewriteEngine On
  <IfModule mod_proxy_http.c>
    RewriteCond %{HTTP_USER_AGENT} baiduspider|facebookexternalhit|twitterbot|rogerbot|linkedinbot|embedly|quora\ link\ preview|showyoubot|outbrain|pinterest|slackbot|vkShare|W3C_Validator [NC,OR]
    RewriteCond %{QUERY_STRING} _escaped_fragment_
    RewriteRule ^(?!.*?(\.js|\.css|\.xml|\.less|\.png|\.jpg|\.jpeg|\.gif|\.pdf|\.doc|\.txt|\.ico|\.rss|\.zip|\.mp3|\.rar|\.exe|\.wmv|\.doc|\.avi|\.ppt|\.mpg|\.mpeg|\.tif|\.wav|\.mov|\.psd|\.ai|\.xls|\.mp4|\.m4a|\.swf|\.dat|\.dmg|\.iso|\.flv|\.m4v|\.torrent|\.ttf|\.woff))(.*) http://service.prerender.io/http://www.my-site.com/$2 [P,L]
  </IfModule>
</IfModule>

I also tried the comment of @benceg just below the post but this also did not work:

RewriteRule ^(?!.*?(\.js|\.css|\.xml|\.less|\.png|\.jpg|\.jpeg|\.gif|\.pdf|\.doc|\.txt|\.ico|\.rss|\.zip|\.mp3|\.rar|\.exe|\.wmv|\.doc|\.avi|\.ppt|\.mpg|\.mpeg|\.tif|\.wav|\.mov|\.psd|\.ai|\.xls|\.mp4|\.m4a|\.swf|\.dat|\.dmg|\.iso|\.flv|\.m4v|\.torrent))(index\.php)?(.*) http://service.prerender.io/%{REQUEST_SCHEME}://%{HTTP_HOST}/$3 [P,L]

The above .htaccess file did not work, and worse yet, when I replaced my previous (the one mentioned at the beginning) fully working .htaccess file back, it was also not working.

When I entered www.my-site.com, it showed me “Website under construction”.

Then I tried www.my-site.com/mycontroller and, to my surprise, my home page was being shown. This clearly indicates that my .htaccess file (which was previously fully working) is now “partially” working.

But again when I tried www.my-site.com, it showed “Website under construction”.

Some codeigniter configurations that I currently have:

$config['base_url'] = 'http://www.my-site.com/';
$config['index_page'] = '';
$config['uri_protocol'] = 'REQUEST_URI';
$route['default_controller'] = 'mycontroller';

I am using Bluehost Shared Hosting service and I know they support mod-rewrite.

I do not want prerender.io anymore. What did I enable or disable while trying the new (prerender.io version) .htaccess? What can I do to get my fully working "previous state" back?

I tried to search the net for similar issues but did not find anything specific to my problem.

Update:

I tried using the first (previously working) .htaccess file on local lampp server and it is working as usual but it is still not working on Bluehost server.

Update 2:

An interesting finding I made today. When I am checking my site's (address: northernschoolofmusic.com.cp-in-13.webhostbox.net) speed on Google, the page is being rendered correctly. But when I am accessing the above mentioned link in a browser I am instantly redirected to http://northernschoolofmusic.com.cp-in-13.webhostbox.net/cgi-sys/defaultwebpage.cgi .

2

There are 2 answers

1
John On BEST ANSWER

The problem was finally the internet connexion. The Internet Provider may have saved the DNS incorrectly and redirected to a wrong cached page. Changing the browser or the connexion provider was the solution !

1
Sorav Garg On

use this htaccess -

RewriteEngine on
RewriteCond $1 !^(index\.php|resources|robots\.txt)
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/$1 [L,QSA] 

and config settings should be like that

$config['base_url'] = 'http://www.my-site.com/';
$config['index_page'] = '';

please follow this it will work...