当用户在我的网站上单击导航链接时,它会使用javascript将页面加载到当前页面的内容窗口中。
然后,我使用HTML5来操作URL并创建一个历史记录条目。所以我留下的URL看起来像问题中的那个(https://someDomain.com/questions)。
问题是,如果我单击刷新或向某人发送链接,它会得到404错误,因为它指向路径名/问题,然后正在寻找索引。
在我的情况下,我正在加载(pages/questions.php).
有没有办法让我的域忽略所有路径名或其他什么,这样我就可以使用location.pathname将我的页面加载到域根的Main index.php中。。。
这是我当前的.htaccess代码
#default index page
DirectoryIndex index.php
#PHP code in HTML file
AddType cgi-script .php .htm .html .phtml
RewriteRule ^/.*$ /index.php
它需要在您的web服务器(例如Apache、IIS等)上进行配置,方法是将每个URL重写为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
上查看一个更全面的解决方案。