Hide URL of PHP page

2019-04-15 03:40发布

问题:

I want to hide the URL of my PHP page; that is, I don't want to write /register.php directly in the href tag, I want to write /register/ and have it open the register.php page directly. I want to do that for all the webpages.

回答1:

In .htaccess try this :

  RewriteCond %{REQUEST_FILENAME} !-f
  RewriteCond %{REQUEST_FILENAME} !-d
  RewriteCond %{REQUEST_URI} !=/favicon.ico
  RewriteRule ^(.*)$ $1.php [L,QSA]


回答2:

You should take a look at mod_rewrite; it's a Apache module that will help you with it.



回答3:

umm quick fix is to make a directory called register and save it as the index.php then make sure all your forms have action="/register/" (assuming register is a root folder of domain)



回答4:

Rest easy .. I am new to web development also and I had trouble making this solution work. The detail that is not obvious is that in the php code links, you should remove the extension. For example :

<li><a href="index.php">Home</a></li> should read <li><a href="index">Home</a></li>

Then the extension goes away.



标签: php url