重定向到目录或文件

时间:2013-03-22 10:01:06

标签: apache .htaccess redirect

这是我的文件结构

-- admin
  |-- css
    |-- style.css
  |-- payments
     |-- index.php
     |-- ajax.php
  |-- index.php
-- public
  |-- css
    |-- style.css
  |-- payments
    |-- index.php
    |-- test.php
  |-- index.php
  |-- test.php
-- .htaccess
-- index.php

如果有人访问该目录,我不希望/index.php文件做任何事情。相反,一切都将由.htaccess控制。

这就是我对.htaccess所拥有的,我必须说的非常混乱。

# Redirect Home
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^$ public/index.php [QSA,L,NC]

# Public Sub-Directories Sub-Directory Pages
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI} !public/(.*)
RewriteCond %{REQUEST_URI} !css(.*)
RewriteCond %{REQUEST_URI} !js(.*)
RewriteRule ^(.*)/(.*)$ public/$1/$2.php [QSA,L,NC]

# Public Sub-Directories
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI} !public/(.*)
RewriteCond %{REQUEST_URI} !css(.*)
RewriteCond %{REQUEST_URI} !js(.*)
RewriteRule ^(.*)$ public/$1/index.php [QSA,L,NC]

# Public Pages
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_URI} !css(.*)
RewriteCond %{REQUEST_URI} !js(.*)
RewriteCond %{REQUEST_URI} !public/(.*)
RewriteRule ^(.*)$ public/$1.php [QSA,L,NC]

# Public Directory Redirects
RewriteRule ^css/(.*)($|/$) public/css/$1 [QSA,L]
RewriteRule ^js/(.*)($|/$) public/css/$1 [QSA,L]

# Admin Redirect
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^admin/modules/([^/\.]+)/([^/\.]+)($|/$) admin/index.php?admin=1&module=$1&p=$2 [QSA,L]

RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^admin/modules/([^/\.]+)($|/$) admin/index.php?admin=1&module=$1 [QSA,L]

RewriteRule ^admin/modules($|/$) admin/index.php?admin=1 [QSA,L]

基本上我正在尝试实现以下重定向:

  • / =发送到/public/index.php
  • / test =发送到/public/test.php
  • /css/style.css =发送到/public/css/style.css
  • / payments =发送至/public/payments/index.php
  • / payments / test =发送至/public/payments/test.php
  • / admin =发送到/admin/index.php
  • / admin / modules / payments =发送至/admin/payments/index.php
  • / admin / modules / payments / ajax =发送至/admin/payments/ajax.php
  • /admin/css/style.css =发送到/public/css/style.css

用户无法看到真实的网址

最终会有更多,但甚至还没有基础知识:(

0 个答案:

没有答案