【问题标题】:Remove file extension and file name删除文件扩展名和文件名
【发布时间】:2016-04-08 19:21:56
【问题描述】:

我使用此代码删除了我网站上的 .php 文件扩展名

Options +FollowSymLinks -MultiViews
# Turn mod_rewrite on
RewriteEngine On
RewriteBase /

## hide .php extension
# To externally redirect /dir/foo.php to /dir/foo
RewriteCond %{THE_REQUEST} ^[A-Z]{3,}\s([^.]+)\.php [NC]
RewriteRule ^ %1 [R,L,NC]

## To internally redirect /dir/foo to /dir/foo.php
RewriteCond %{REQUEST_FILENAME}.php -f
RewriteRule ^ %{REQUEST_URI}.php [L]

这可以将我的 url 从 example.com/contact/contact.php 更改为 example.com/contact/contact,但我希望 url 在它所在的文件夹之后没有文件名。我想要它看起来像 example.com/contact/ 有什么想法吗?

【问题讨论】:

  • 如果文件夹/contact/ 也有另一个像main.php 这样的php 文件,那么该文件的URL 是什么?
  • 我认为您应该将文件移动到您的网站根目录。

标签: php html .htaccess url


【解决方案1】:

一个简单的方法是在导航到文件夹时命名文件 index.php,index.php 文件将被提供。 所以导航到/contact的时候会显示/contact/index.php。

https://en.wikipedia.org/wiki/Webserver_directory_index

【讨论】:

    猜你喜欢
    • 2013-04-12
    • 2012-05-12
    • 1970-01-01
    • 1970-01-01
    • 2012-06-29
    • 1970-01-01
    • 2019-01-03
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多