除特定子目录外,Htaccess总是重定向到索引

时间:2014-06-13 22:34:35

标签: php apache .htaccess mod-rewrite redirect

所以我有这个任务,我必须在一个域下基本上制作两个网页。主页必须经过index.php。除了/子目录(在子目录下有另一个网页) - 然后使用子目录

示例:

  • example.com - >转到index.php
  • example.com/subdirectory - >转至/subdirectory/index.php
  • example.com/subdirectory/peter - >转到/子目录/ peter /
  • example.com/example2 - >转到index.php

这是我目前管理的内容:

    #If 
    RewriteCond %{HTTP_HOST} ^(www.)?example.com$
    RewriteCond %{REQUEST_URI} !/subdirectory/index.php
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    # rewrite
    RewriteRule ^(.*)$ /forums/$1 [L]
    # IF
    RewriteCond %{HTTP_HOST} ^(www.)?example.com$
    RewriteCond %{REQUEST_URI} !/index.php
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    # rewrite
    RewriteRule ^(/)?$ index.php [L]

老实说,我没有想法......

了解如何操作:

RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php?q=$1 [L,QSA]

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI} !/forums
RewriteRule ^(.*)$ index.php?q=$1 [L,QSA]

至今它的工作原理。

0 个答案:

没有答案