Php 将htaccess与Codeigniter和特定规则一起使用

Php 将htaccess与Codeigniter和特定规则一起使用,php,.htaccess,codeigniter,Php,.htaccess,Codeigniter,我无法将特定的重写规则添加到存在codeigniter重写规则的.htaccess文件中 Options -Indexes Options +FollowSymLinks <IfModule mod_rewrite.c> RewriteEngine On RewriteCond %{HTTPS} off RewriteRule .* https://%{HTTP_HOST}

我无法将特定的重写规则添加到存在codeigniter重写规则的.htaccess文件中

              Options -Indexes
      Options +FollowSymLinks



      <IfModule mod_rewrite.c>
         RewriteEngine On
         RewriteCond %{HTTPS} off
         RewriteRule .* https://%{HTTP_HOST}%{REQUEST_URI}

         RewriteCond %{REQUEST_FILENAME} !-f
         RewriteCond %{REQUEST_FILENAME} !-d
         RewriteCond $1 !^(index\.php|images|robots\.txt|css|docs|js|system|sayfalar|main\.php)
         RewriteRule ^(.*)$ /index.php?/$1 [L]


        RewriteCond %{REQUEST_FILENAME} !-f
        RewriteCond %{REQUEST_FILENAME} !-d
        RewriteRule ^main/(.*)$ /main.php?tag=$1 [L,NC]

        DirectoryIndex home.php
      </IfModule>
选项-索引
选项+FollowSymLinks
重新启动发动机
重写条件%{HTTPS}关闭
重写规则。*https://%{HTTP_HOST}%{REQUEST_URI}
重写cond%{REQUEST_FILENAME}-F
重写cond%{REQUEST_FILENAME}-D
1美元^(索引\.php | images | robots\.txt | css | docs | js | system | sayfalar | main\.php)
重写规则^(.*)$/index.php?/$1[L]
重写cond%{REQUEST_FILENAME}-F
重写cond%{REQUEST_FILENAME}-D
重写规则^main/(.*)$/main.php?标记=$1[L,NC]
DirectoryIndex home.php
部分
RewriteRule^main/(.*)$/main.php?标记=$1[L,NC]
根本不工作

当我键入main.php?tag=decoration对应的site.com/main/decoraion时,我得到了Codeigniter的404错误页面。CODEIGITITER的规则处理请求,尽管我告诉HTTAccess在重写

时不要考虑Maun.PHP文件。
添加此规则的正确方法是什么?

您应该交换这两个规则:

<IfModule mod_rewrite.c>
    RewriteEngine On
    RewriteCond %{HTTPS} off
    RewriteRule .* https://%{HTTP_HOST}%{REQUEST_URI}

    # => Put your specific rule here !
    RewriteRule ^main/(.*)$ /main.php?tag=$1 [L,NC]

    # The remaining route, acting as a "catch-all"
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    # I'm not really sure the purpose of your next condition, but I suspect it's useless. See comment.
    #RewriteCond $1 !^(index\.php|images|robots\.txt|css|docs|js|system|sayfalar|main\.php)
    RewriteRule ^(.*)$ /index.php?/$1 [L]

    DirectoryIndex home.php
</IfModule>

重新启动发动机
重写条件%{HTTPS}关闭
重写规则。*https://%{HTTP_HOST}%{REQUEST_URI}
#=>将您的具体规则放在这里!
重写规则^main/(.*)$/main.php?标记=$1[L,NC]
#剩下的路线,充当“一网打尽”
重写cond%{REQUEST_FILENAME}-F
重写cond%{REQUEST_FILENAME}-D
#我不确定你下一个条件的目的,但我怀疑这是没有用的。见评论。
#1美元^(索引\.php | images | robots\.txt | css | docs | js | system | sayfalar | main\.php)
重写规则^(.*)$/index.php?/$1[L]
DirectoryIndex home.php
只是提醒你,[L]意味着如果匹配,这个规则应该是最后一个应用的规则

因此,当您执行
RewriteRule^(.*)$/index.php?/$1[L]
时,您告诉Apache匹配任何URL并将其重写到您的索引中,并且不要寻找进一步的规则。这就是你的问题


因此,主要的方法是在末尾重写到索引(就像“一网打尽”),并在前面添加特定的路由

您应该交换这两条规则:

<IfModule mod_rewrite.c>
    RewriteEngine On
    RewriteCond %{HTTPS} off
    RewriteRule .* https://%{HTTP_HOST}%{REQUEST_URI}

    # => Put your specific rule here !
    RewriteRule ^main/(.*)$ /main.php?tag=$1 [L,NC]

    # The remaining route, acting as a "catch-all"
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    # I'm not really sure the purpose of your next condition, but I suspect it's useless. See comment.
    #RewriteCond $1 !^(index\.php|images|robots\.txt|css|docs|js|system|sayfalar|main\.php)
    RewriteRule ^(.*)$ /index.php?/$1 [L]

    DirectoryIndex home.php
</IfModule>

重新启动发动机
重写条件%{HTTPS}关闭
重写规则。*https://%{HTTP_HOST}%{REQUEST_URI}
#=>将您的具体规则放在这里!
重写规则^main/(.*)$/main.php?标记=$1[L,NC]
#剩下的路线,充当“一网打尽”
重写cond%{REQUEST_FILENAME}-F
重写cond%{REQUEST_FILENAME}-D
#我不确定你下一个条件的目的,但我怀疑这是没有用的。见评论。
#1美元^(索引\.php | images | robots\.txt | css | docs | js | system | sayfalar | main\.php)
重写规则^(.*)$/index.php?/$1[L]
DirectoryIndex home.php
只是提醒你,[L]意味着如果匹配,这个规则应该是最后一个应用的规则

因此,当您执行
RewriteRule^(.*)$/index.php?/$1[L]
时,您告诉Apache匹配任何URL并将其重写到您的索引中,并且不要寻找进一步的规则。这就是你的问题


因此,主要的方法是在末尾重写到索引(就像“一网打尽”),并在前面添加特定的路由

“添加此规则的正确方法是什么?”-可能没有,因为尝试再次匹配该模式一开始就没有什么意义
^(.*)$
只是任何路径,CI已经在将其重写到index.php本身。
^main/(.*)$
在我键入与main.php相对应的site.com/main/decoration?tag=decoration时工作不正常。那么,您在哪里尝试添加此规则呢?你至少检查过错误日志上写的是什么吗?它们在同一个文件中。当我输入site.com/main/decoration时,我会看到Codeigniter的404错误页面。我猜Codeigniter的重写规则会处理请求“添加此规则的正确方法是什么?”——可能没有,因为尝试再次匹配该模式一开始就毫无意义
^(.*)$
只是任何路径,CI已经在将其重写到index.php本身。
^main/(.*)$
在我键入与main.php相对应的site.com/main/decoration?tag=decoration时工作不正常。那么,您在哪里尝试添加此规则呢?你至少检查过错误日志上写的是什么吗?它们在同一个文件中。当我输入site.com/main/decoration时,我会看到Codeigniter的404错误页面。我猜Codeigniter的重写规则会处理requestNote,我真的不确定你想对条件
RewriteCond$1做什么^(index\.php | images | robots\.txt | css | docs | js | system | sayfalar | main\.php)
。我知道你想忽略文件/文件夹,这是没有用的,因为前面的条件
-f
-d
正好可以。就是这样:)谢谢。我想感谢@04FS的关注。注意,我不太确定你想对条件
RewriteCond$1做什么^(index\.php | images | robots\.txt | css | docs | js | system | sayfalar | main\.php)
。我知道你想忽略文件/文件夹,这是没有用的,因为前面的条件
-f
-d
正好可以。就是这样:)谢谢。我要感谢@04FS的关注