I have seen in WordPress, when you create a page say “Register”, it points to http://example.com/register/ but without having a folder named register in the root at all. How is this done?
Its like this. When a user clicks the link on http://example.com/index.php which says Register, it takes the user to a new page and the URL in the browser would be http://example.com/register/ and the page loads. The register folder itself does not exist.
From the answers below I learnt that the request is passed through the index.php by modifying the .htaccess
I want to know what code to place in index.php so that http://example.com/register/ would display the register page.
In my WordPress .htaccess file I have:
Which basically says if the “filename” part of the URL doesn’t exist as a file
!-for exist as a directory!-dthen rewrite the request internally to be/index.phpwhich forces the request to be processed byindex.phpof WordPress.Ok, based on your additional comments, the following
.htaccessrules will takehttp://domain.com/<anything>and internally rewrite it tohttp://domain.com/index.php?page=<anything>, this will be done without regard to case (NCflag) and will keep (pre-pend) any existing query string (QSAflag). This only does this for filenames and directories that do not exist on the server.This does have the following side effect which you should be able to handle programmatically,
http://domain.com/register/will be rewritten tohttp://domain.com/index.php?page=register/which includes the trailing “/” since this is a directory reference. Again, you should be able to handle that in your PHP code.