删除扩展名为.php(明确写入)为友好的URL友好、明确、php、URL

由网友(校长是皇后╮老师是容嬷嬷)分享简介:htaccess的删除了我的网站的文件扩展名.php。htaccess to remove the .php extension of my site's files.RewriteEngine onRewriteBase /RewriteCond %{SCRIPT_FILENAME} !-dRewrite...

htaccess的删除了我的网站的文件扩展名.php。

htaccess to remove the .php extension of my site's files.

RewriteEngine on
RewriteBase /
RewriteCond %{SCRIPT_FILENAME} !-d
RewriteCond %{SCRIPT_FILENAME} !-f
RewriteRule ^(.*)$ $1.php [L,QSA]

现在,如果我去我的网站

Now, if I go to my site

www.mysite.com/home

工作正常,它重定向到home.php但是URL仍然友好。

works fine, it redirects to home.php but the URL is still friendly.

但是,如果我写这篇文章的网址:

But if I write this URL:

www.mysite.com/home.php

该home.php供应和URL并不友好。

The home.php is served, and the URL is not friendly.

我怎样才能避免这种情况?我想,如果用户写www.mysite.com/home.php,在URL栏中显示的URL进行www.mysite.com/home~~V

How can I avoid this behavior? I want that if the user writes www.mysite.com/home.php, the URL displayed in the URL bar be www.mysite.com/home

推荐答案

您可以从像这样

RewriteCond %{REQUEST_URI} ^/(.*).php$
RewriteRule ^(.*)$ %1 [L,QSA]
阅读全文

相关推荐

最新文章