当用户点击我网站上的导航链接时,它会使用javascript将页面加载到当前页面上的内容窗口中。
然后我使用HTML 5来操作URL并创建历史记录条目。所以我留下的网址就像问题中的网址(https://someDomain.com/questions)。
问题是,如果我点击刷新或向某人发送链接,则会收到404错误,因为它会转到路径名/问题,然后查找索引。
在我的情况下我正在加载(pages / questions.php)。
有没有办法让它这样我的域忽略所有的路径名或者什么东西,所以我可以使用location.pathname将我的页面加载到域的根目录下的主索引.ph。
这是我当前的.htaccess代码
#default index page
DirectoryIndex index.php
#PHP code in HTML file
AddType cgi-script .php .htm .html .phtml
RewriteRule ^/.*$ /index.php
答案 0 :(得分:0)
需要在您的网络服务器(例如Apache,IIS等)上进行配置,方法是重写index.php
的每个网址。
例如,在Apache中,它是使用.htaccess
中的RewriteRules完成的,对于您的情况,这样做会发送任何请求到文件index.php:
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php
</IfModule>
如果它确实是Apache,您可以在WordPress' .htaccess
查看更全面的解决方案。