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 求解O-S方程的特征值问题给出边界层布拉休斯平行流的中性曲线
  • ¥15 谁有desed数据集呀
  • ¥20 手写数字识别运行c仿真时,程序报错错误代码sim211-100
  • ¥15 关于#hadoop#的问题
  • ¥15 (标签-Python|关键词-socket)
  • ¥15 keil里为什么main.c定义的函数在it.c调用不了
  • ¥50 切换TabTip键盘的输入法
  • ¥15 可否在不同线程中调用封装数据库操作的类
  • ¥15 微带串馈天线阵列每个阵元宽度计算
  • ¥15 keil的map文件中Image component sizes各项意思