开发者

Hide extension in .htaccess

开发者 https://www.devze.com 2023-02-27 01:30 出处:网络
Hi All i have a problem that my file have .html extention but i want that whenthe fi开发者_如何学JAVAle open in brownser the extention had hidden.e.g file.html to file.

Hi All i have a problem that my file have .html extention but i want that when the fi开发者_如何学JAVAle open in brownser the extention had hidden.e.g file.html to file. Advance thanks


In your .htaccess file use this:

RewriteEngine on  
RewriteCond %{REQUEST_FILENAME} !-d  
RewriteCond %{REQUEST_FILENAME}\.html -f  
RewriteRule ^(.*)$ $1.html

Now you can use lins like http://www.mysite.com/contact rather than http://www.mysite.com/contact.html.

Hope this helps!


RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^([^/]+)/$ $1.php
RewriteRule ^([^/]+)/([^/]+)/$ /$1/$2.php
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI} !(\.[a-zA-Z0-9]{1,5}|/)$
RewriteRule (.*)$ /$1/ [R=301,L]

Example yoursite.com/wallpaper.html to yoursite.com/wallpaper/


Your link must be like this

<a href="example">Example</a>
 Instead of
<a href="example.php">Example</a>

Then add this to your .htaccess file

 RewriteCond ^example example.php [L]


RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}.html -f
RewriteRule ^(.*)$ $1.html

this one is ok for single extensions in one website. I am using multiple extensions in same website for example index.html and contact.php.

How can i use this code ?

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号