简体   繁体   English

使用htaccess使用加载程序重定向站点根目录

[英]Using htaccess to redirect site root with loader

The site I've taken over from someone else uses a loader on the index page to pull in the correct pages based on what URL is requested. 我从别人那里接管的网站使用索引页面上的加载器,根据请求的URL提取正确的页面。 For example, if you request http://example.com/services it knows to pull in the services.php page from the "views" folder. 例如,如果您请求http://example.com/services,它将知道从“ views”文件夹中拉入services.php页面。 It is using htaccess to rewrite the URLs with the following 它正在使用htaccess用以下内容重写URL

RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^([^/(.*)]+)$   ?$1 [L]
RewriteRule ^([^/(.*)]+)/$  ?$1 [L]

This all works great except for when you request the homepage by simply going to http://example.com in which case it throws a 500 error. 所有这些都非常有用,除了您通过简单地转到http://example.com来请求首页时(在这种情况下,它会引发500错误)。 If I attempt to access /index it pulls the appropriate index view as expected. 如果我尝试访问/ index,它将按预期提取适当的索引视图。

Error Log that my host gives me (not much I'm afraid, just 404s from the 500 page not being found) 我的主机给我的错误日志(恐怕不多,找不到500页中的404个)

[Wed Oct 29 15:51:41 2014] [error] [client 216.54.92.21] File does not exist: /home/hotwater/public_html/500.shtml
[Wed Oct 29 15:48:56 2014] [error] [client 216.54.92.21] File does not exist: /home/hotwater/public_html/500.shtml
[Wed Oct 29 15:48:47 2014] [error] [client 216.54.92.21] File does not exist: /home/hotwater/public_html/500.shtml

This site was working on a previous host but the homepage broke when we transferred it over to a new host and I can't seem to get it working myself. 该站点在以前的主机上工作,但是当我们将其转移到新主机上时,主页破裂了,我似乎无法自己工作。 Any help is appreciated. 任何帮助表示赞赏。

Problem seems to be in your regex and and one last RewriteRule with any RewriteCond . 问题似乎出在您的正则表达式中,还有最后一个RewriteRule和任何RewriteCond Use this rule instead: 请改用以下规则:

ErrorDocument 404 default
ErrorDocument 500 default
DirectoryIndex index.php
Options +FollowSymLinks
RewriteEngine On

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^([^/.]+)/?$ ?$1 [L,QSA]

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM