简体   繁体   中英

How do I ignore all pathNames and load my index.php at the root of my site?

When a user clicks a nav link on my web site it loads the page into a content window on the current page with javascript.

I then use HTML 5 to manipulate the URL and create a history entry. So the URL I am left with looks like the one in the question ( https://someDomain.com/questions ).

The problem is if I click refresh or send someone the a link it gets a 404 error because it is going to the pathname /questions and is then looking for an index.

In my case I am loading (pages/questions.php).

Is there a way to make it so my domain ignores all pathNames or something so I can then use the location.pathname to do my page loading into my Main index.php at the root of the domain...

Here is my current .htaccess code

#default index page
DirectoryIndex index.php

#PHP code in HTML file
AddType cgi-script .php .htm .html .phtml

RewriteRule ^/.*$ /index.php

It needs to be configured at your web server (eg Apache, IIS, etc.), by rewriting every URL to your index.php .

For example, in Apache it is done using RewriteRules in .htaccess , for your case something like this will do it - send any request to the file index.php:

<IfModule mod_rewrite.c>
  RewriteEngine On
  RewriteBase /
  RewriteCond %{REQUEST_FILENAME} !-f
  RewriteCond %{REQUEST_FILENAME} !-d
  RewriteRule . /index.php
</IfModule>

If it's indeed Apache, you can check a more comprehensive solution for this at WordPress' .htaccess .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM