[英]How do I ignore all pathNames and load my index.php at the root of my site?
当用户单击我的网站上的导航链接时,它将使用javascript将页面加载到当前页面的内容窗口中。
然后,我使用HTML 5操纵URL并创建一个历史记录条目。 因此,剩下的URL看起来像是问题中的URL( https://someDomain.com/questions )。
问题是如果我单击“刷新”或向某人发送链接,它会收到404错误,因为它将转到路径名/ questions,然后正在寻找索引。
就我而言,我正在加载(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
需要通过将每个URL重写为index.php
来在您的Web服务器(例如Apache,IIS等)上对其进行配置。
例如,在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
查看更全面的解决方案。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.