问题
I'm running an AJAX enabled site that caters for HTML4 hash and HTML5 pushstate().
I've just migrated to an AWS EC2 instance (linux server running apache) and both site are running fine.
The only issue I've experienced is when I refresh a HTML4 hash page the correct page shows.
However when I refresh a HTML5 page like http://www.datingjapan.co/conversations I get the following error message:
It appears that apache is trying to go into the folder 'converstations' rather then just call the site 'index.php' which then using jquery to load the correct page.
Can anyone advise what might be the issue here. I'm assuming its a httpd.conf settings.
thx
回答1:
If you're trying to use an index.php
file as some type of bootstrap you might want to try this in your .htaccess
file:
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteCond %{HTTP_HOST} !^(www\.).+$ [NC]
RewriteRule ^(.*)$ http://www.%1/$1 [R=301,L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-l
RewriteRule ^(.*)$ index.php?/$1 [L]
</IfModule>
Basically this will redirect all request from non-www to www and then if its not a file or a directory it will forward the request to the index.php
file.
回答2:
I haven’t used pushState()
myself, but if the browser is sending a request for /conversations
to www.datingjapan.co, then Apache will indeed look for a file or folder called “conversations” in its document root, unless you tell it to do something different.
If you want all URLs on www.datingjapan.co to be handled by one index.php file, then you can use the AliasMatch directive in your Apache settings file:
AliasMatch ^.*$ /index.php
I think this will result in all URLs being handled by index.php. (I’m not very hot on Apache configuration though, so I could be wrong.)
来源:https://stackoverflow.com/questions/14034082/httpd-conf-and-html5-pushstate