且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

如何从URL加载Ajax内容使用了哈希

更新时间:2023-12-05 08:21:46

请务必重定向到的pushState工作相对路径。 /对,而不是整个URL。

Be sure to redirect to a relative path for pushState to work. /about, and not the whole URL.

那么,您需要在Web服务器上的重定向。在阿帕奇比如你可以设置在.htaccess,这说/约应该去的index.php /约(或其他) - 在那里你将采取的关于从URL和加载你需要什么,并给这个回用户。

Then you will need a redirection on the web server. In apache for example you can set this in .htaccess, that says that /about should go to index.php/about (or whatever) - and there you will take the "about" from the URL and load what you'll need and give this back to the user.

阿帕奇例如重定向的一切,但静态文件和目录的index.php:

Apache example redirection for everything but static files and directories to index.php:

RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule (.*) index.php?$1 [QSA,L]