douren5490 2017-08-21 12:01
浏览 50

使用尾部斜杠PHP Htaccess删除索引,index.php错误句柄

I need some help with my Htaccess code.

RewriteEngine On
RewriteBase /
RewriteCond %{THE_REQUEST} /([^.]+)\.php [NC]
RewriteRule (.*)\.php$ $1 [R=301]
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI} /$
RewriteRule (.*)/ $1 [R=301]
RewriteCond %{REQUEST_FILENAME}.php -f
RewriteCond %{REQUEST_URI} !/$
RewriteRule (.*) $1\.php [L,QSA]

My Directory Structure is:



Now the above htaccess code is removing the .php extension from the URL.


 -> ->
 -> ->

Problems with this Htaccess File

  1. I want to hide the index too Example: ->

  2. If user types then he should be redirected to

  3. If user type things which do not exist then it should point to

    Example:*/// ->

  4. When it removes the .php extension then a trailing slash should be added to the end.

Example: ->

  1. If a user wants to access create.php and enter /create without / at the end then it should be automatically added.

    Example: ->

In other words, if after removing .php these both works as same

**Example:** =
  1. But user should still be able to access the directory

    Example: ->

    Here 2 is a folder.

I have some problem with this htaccess script. I searched a lot on Google and Stack Overflow but still can't find any solution.

*This is not a duplicate question. Please check it carefully before marking it as a duplicate. I would be glad if you help me.

  • 写回答

1条回答 默认 最新


      相关推荐 更多相似问题


      • ¥15 如何修改为正确的?求解决
      • ¥15 django访问管理员界面问题
      • ¥20 python homework完成
      • ¥20 求解 多变量系统的最小二乘辨识问题的推导以及matlab仿真
      • ¥15 arduino esp8266 Blinker编译报问题
      • ¥15 ubuntu18.04运行模型,直接死机
      • ¥30 (问卷调查)莫名其妙丢了u盘,你们会是什么心理状态
      • ¥100 Spark+android应⽤案例
      • ¥15 yolov8 目标检测 重叠 遮挡
      • ¥20 微信聊天记录如何部署到服务器上