dora12345678 2015-07-06 13:28
浏览 69
已采纳

Htaccess,如果文件夹存在则重定向

I'm trying to redirect the user if the folder install exists but i had no luck so far.

Below is my htaccess file.

RewriteEngine On
RewriteBase /enc/project/
# If the setup directory exists in the document root...
RewriteCond %{DOCUMENT_ROOT}/install -d
# ...and you're not in isntall..
RewriteCond %{REQUEST_URI} !(install) [NC]
# ...redirect to setup - with a 302 (temporary redirect) to make sure the browser won't cache the redirect.
RewriteRule ^(.*) /install [L,redirect=302]
# ...rest of htaccess for codeigniter
RewriteCond %{REQUEST_URI} ^system.*
RewriteRule ^(.*)$ /index.php/$1 [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/$1 [L]

The codeigniter project is in the /enc/project/ in my server thats why the RewriteBase.

Project Structure is

htdocs/enc/project/
|-- application/
|   |-- project
|
|-- system/
|   |-- project
|
|-- install/
|   |-- test/
|   |   |-- test_main.php
|   |   
|   |-- index.php
|
|-- htaccess
  • 写回答

2条回答 默认 最新

  • duanken7168 2015-07-07 08:54
    关注

    Try these rules

    RewriteEngine On
    RewriteBase /enc/project/
    
    # If the setup directory exists in the document root...
    RewriteCond %{DOCUMENT_ROOT}/enc/project/install -d
    # ...and you're not in isntall..
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    # ...redirect to setup - with a 302 (temporary redirect) to make sure the browser won't cache the redirect.
    RewriteRule !^install/ install/ [L,NC,R=302]
    
    # ...rest of htaccess for codeigniter
    RewriteCond %{REQUEST_URI} ^system.*
    RewriteRule ^(.*)$ /index.php/$1 [L]
    
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule ^(.*)$ index.php/$1 [L]
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 深度学习残差模块模型
  • ¥20 两个不同Subnet的点对点连接
  • ¥50 怎么判断同步时序逻辑电路和异步时序逻辑电路
  • ¥15 差动电流二次谐波的含量Matlab计算
  • ¥15 Can/caned 总线错误问题,错误显示控制器要发1,结果总线检测到0
  • ¥15 C#如何调用串口数据
  • ¥15 MATLAB与单片机串口通信
  • ¥15 L76k模块的GPS的使用
  • ¥15 请帮我看一看数电项目如何设计
  • ¥23 (标签-bug|关键词-密码错误加密)