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.
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>
I think there are two problems here:
Your link <a href="mypage.php">My Page</a>
should be <a href="mypage">My Page</a>
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 .php
extension.
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.