0

Whenever a user clicks a link like www.mywebsite.com/hello.php, I want www.mywebsite.com to appear in his address bar. I tried modifying the .htaccess file for this. The rules worked for the home page. But whenever I click a link, the php page for that link appears in the address bar. How can I hide the names of page even after a link is clicked.

RewriteEngine On
RewriteRule ^site$ /*.php [L]

Eg. When I type mywebsite.com/index.php it shows only mywebsite.com. But if I click a link in the page, like <a href="mypage.php">My Page</a>, mywebsite.com/mypage.php appears in the URL.

chris85
  • 23,846
  • 7
  • 34
  • 51
sivavvit
  • 21
  • 1
  • 3

2 Answers2

0

In .htaccess, add a redirection rule for each of your paths. Each rule will tell the server which webpage to serve when the browser requests a human friendly paths. For instance:

Rewrite On
RewriteRule ^home/?$          /home.php      [END,NC]
RewriteRule ^about/?$         /about.php     [END,NC]
RewriteRule ^products/?$      /pages/products.php      [END,NC]
...

Then in your pages, use the pretty links for hrefs:

<a href="/products">Products</a>
BeetleJuice
  • 39,516
  • 19
  • 105
  • 165
0

I think there are two problems here:

  1. Your link <a href="mypage.php">My Page</a> should be <a href="mypage">My Page</a>

  2. From what I understand you don't only want one specific URL to be forwarded, so you should write a more general rule like RewriteRule ^(.*)$ $1.php. This lets you access any URL without the .phpextension.

jkemming
  • 722
  • 12
  • 19