简体   繁体   中英

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. For example, if you request http://example.com/services it knows to pull in the services.php page from the "views" folder. It is using htaccess to rewrite the URLs with the following

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. If I attempt to access /index it pulls the appropriate index view as expected.

Error Log that my host gives me (not much I'm afraid, just 404s from the 500 page not being found)

[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 . 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]

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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