duandi1636 2015-09-07 10:06
浏览 58

在不更改url的情况下将“public / index.php”添加到所有请求

I want to add public/index.php to all request using .htaccess

I tried like this

RewriteEngine on
RewriteRule ^/(.*)$ /public/index.php/$1 [NC,L]

but it didn't changed ..

Example :

If i type

localhost/project/first

it should request

localhost/project/public/index.php/first

What is the issue in my .htaccess ?

  • 写回答

1条回答 默认 最新

  • drsdvwsvo78320812 2015-09-07 10:29
    关注

    You can use a rule like this in /project/.htaccess:

    RewriteEngine On
    RewriteBase /project/
    
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule ^(.*)$ public/index.php/$1 [L]
    

    And this is /project/public/.htaccess:

    <IfModule mod_negotiation.c>
        Options -MultiViews
    </IfModule>
    
    RewriteEngine On
    RewriteBase /project/public/
    
    RewriteRule index\.php$ - [L,NC]
    
    # Redirect Trailing Slashes...
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule ^(.+?)/$ /$1 [L,R=301,NE]
    
    # Handle Front Controller...
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteRule ^ index.php [L]
    

    RewriteCond are required to avoid rewriting for real files and directories. And There shouldn't be any leading slash in RewriteRule pattern in .htaccess. .htaccess is per directory directive and Apache strips the current directory path (thus leading slash) from RewriteRule URI pattern.

    评论

报告相同问题?

悬赏问题

  • ¥15 如何用Labview在myRIO上做LCD显示?(语言-开发语言)
  • ¥15 Vue3地图和异步函数使用
  • ¥15 C++ yoloV5改写遇到的问题
  • ¥20 win11修改中文用户名路径
  • ¥15 win2012磁盘空间不足,c盘正常,d盘无法写入
  • ¥15 用土力学知识进行土坡稳定性分析与挡土墙设计
  • ¥70 PlayWright在Java上连接CDP关联本地Chrome启动失败,貌似是Windows端口转发问题
  • ¥15 帮我写一个c++工程
  • ¥30 Eclipse官网打不开,官网首页进不去,显示无法访问此页面,求解决方法
  • ¥15 关于smbclient 库的使用