【问题标题】:Previously working .htaccess in codeigniter 3.1.2 not working after trying prerender.io以前在 codeigniter 3.1.2 中工作的 .htaccess 在尝试 prerender.io 后无法工作
【发布时间】:2016-12-24 14:39:35
【问题描述】:

我在 .htaccess 文件中使用了以下配置:

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

一切正常,我一进入 www.my-site.com 就显示主页。

然后我尝试使用此链接中提供的 .htaccess 文件在 codeigniter 中实现 prerender.io:https://gist.github.com/thoop/8072354。新的.htaccess文件如下:

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

我还尝试了帖子下方@benceg 的评论,但这也没有用:

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]

上面的 .htaccess 文件不起作用,更糟糕的是,当我将以前的(开头提到的)完全正常工作的 .htaccess 文件替换回来时,它也不起作用。

当我进入 www.my-site.com 时,它显示“网站正在建设中”。

然后我尝试了 www.my-site.com/mycontroller,令我惊讶的是,我的主页正在显示。这清楚地表明我的 .htaccess 文件(以前可以完全工作)现在“部分”工作。

但是当我再次尝试 www.my-site.com 时,它显示“网站正在建设中”。

我目前拥有的一些 codeigniter 配置:

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

我正在使用 Bluehost 共享主机服务,我知道他们支持 mod-rewrite。

我不再想要 prerender.io。在尝试新的(prerender.io 版本).htaccess 时我启用或禁用了什么?我可以做些什么来恢复我完全正常工作的“以前的状态”?

我试图在网上搜索类似的问题,但没有找到任何特定于我的问题的内容。

更新:

我尝试在本地lampp服务器上使用第一个(以前工作的).htaccess文件,它像往常一样工作,但它仍然不能在Bluehost服务器上工作。

更新 2:

我今天做了一个有趣的发现。当我在 Google 上检查我的网站(地址:northschoolofmusic.com.cp-in-13.webhostbox.net)的速度时,页面正在正确呈现。但是当我在浏览器中访问上述链接时,我会立即被重定向到http://northernschoolofmusic.com.cp-in-13.webhostbox.net/cgi-sys/defaultwebpage.cgi。

【问题讨论】:

  • @John 我试图重置。但结果是一样的。即使删除 public_html 文件夹中的 index.html 文件,仍然显示“正在构建的页面”。
  • @RajaMukherjee 你试过 Sorav Garg 评论解决方案吗?
  • @John 是的,我试过了。但它没有用。我要求 Bluehost 将我帐户的文件管理器部分恢复出厂设置。他们还没有回复。
  • 好吧好吧。之后让我知道。你网站的网址是什么?
  • @John (临时)网址是 northernschoolofmusic.com.cp-in-13.webhostbox.net 。但即使在删除默认的 index.html 文件之后,它也给了我一个很大的“抱歉”。所以我不得不使用northernschoolofmusic.com.cp-in-13.webhostbox.net/nsm。

标签: php apache .htaccess codeigniter prerender


【解决方案1】:

问题最终出在互联网连接上。 Internet 提供商可能错误地保存了 DNS 并重定向到错误的缓存页面。 更改浏览器或连接提供商是解决方案!

【讨论】:

  • 感谢大家的帮助。
【解决方案2】:

使用这个 htaccess -

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

配置设置应该是这样的

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

请按照此操作...

【讨论】:

  • 感谢您的解决方案。但我很遗憾地说它在我的情况下不起作用。我要求 Bluehost 将我帐户的文件管理器部分恢复出厂设置。他们还没有回复。
猜你喜欢
  • 2016-02-14
  • 2012-05-07
  • 1970-01-01
  • 2016-03-01
  • 2012-04-29
  • 2016-02-09
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多