【问题标题】:htaccess for codeIgniter用于 codeIgniter 的 htaccess
【发布时间】:2013-04-23 02:12:12
【问题描述】:

如果 URL 中没有 /hd/,我正在尝试将用户重定向到 /hd/142。我尝试了很多选择,其中大多数只是一遍又一遍地重定向我。这是我设置的当前.htaccess

RewriteEngine on
RewriteCond $1 !^(index\.php|images|css|js)
RewriteRule ^hd/(.*)$ /index.php/$1 [L]
RewriteRule ^(images|css|js)/(.*) /applicationFiles/$1/$2 [L]

谢谢

【问题讨论】:

    标签: .htaccess codeigniter redirect


    【解决方案1】:
    RewriteEngine on
    RewriteBase / 
    
    #if url does not have hd in it
    RewriteCond %{REQUEST_URI} !^/hd/ [NC]
    #redirect to hd
    RewriteRule ^  /hd/142 [L,R=301]  
    
    #existing rules
    RewriteCond $1 !^(index\.php|images|css|js) [NC]
    RewriteRule ^hd/(.*)$ /index.php/$1 [L,NC]
    RewriteRule ^(images|css|js)/(.*) /applicationFiles/$1/$2 [L]
    

    【讨论】:

      【解决方案2】:

      一个简单的解决方案是在 codeigniter 中使用 routes.php:

      $route['^(hd)'] = '/hd/142';
      

      在此处阅读正则表达式部分的更多信息:http://codeigniter.com/user_guide/general/routing.html

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2013-11-03
        • 1970-01-01
        • 2012-05-16
        • 2014-09-23
        • 2018-08-30
        相关资源
        最近更新 更多