将规则重写为子文件夹

时间:2015-10-01 20:51:57

标签: .htaccess mod-rewrite

我的网站位于子文件夹

/application
/application/php  (all php files)
/application/view (my templates files)
/application/admin (my admin) 

在我的.htaccess上我对主文件有这个限制

RewriteRule ^(.+)\/?([0-9]*)\/?$ application/php/index.php

我的网站完美无缺

www.mysite.com/ 

现在我想重写管理文件夹的规则

www.mysite.com/admin  read /application/admin/

我试过这样的事情,但是没有工作

RewriteRule admin/^(.+)\/?([0-9]*)\/?$ application/admin/index.php

我的FUll .htaccess

RewriteEngine On

RewriteCond %{REQUEST_FILENAME} !^(.+)\.(css|js|xml|swf|flv|pdf)$
RewriteCond %{REQUEST_FILENAME} !^(.+)\.(jpg|jpeg|png|gif)$
RewriteCond %{REQUEST_FILENAME} !^(.+)\.(ttf|otf|eot|woff|svg)$
RewriteCond %{REQUEST_FILENAME} !cron.php
RewriteCond %{REQUEST_FILENAME} !/cache
RewriteCond %{REQUEST_FILENAME} !favicon.ico
RewriteCond %{REQUEST_FILENAME} !robots.txt
RewriteCond %{REQUEST_FILENAME} !ajax.php
RewriteCond %{REQUEST_FILENAME} !sitemap.xml
RewriteCond %{REQUEST_FILENAME} !/template/(.*)\.html
RewriteCond %{REQUEST_FILENAME} !/application/inc/OAuth(.*)\.php


RewriteRule ^(.+)\/?([0-9]*)\/?$ application/php/index.php
#RewriteRule admin/^(.+)\/?([0-9]*)\/?$ application/admin/index.php  (not work)


 <IfModule mod_expires.c>
 <FilesMatch "\.(ico|gif|jpg|jpeg|png|js|css)$">
    ExpiresActive On
    ExpiresDefault "access plus 30 days"
    FileETag None
 </FilesMatch>
 <FilesMatch "\.(xml|php)$">
    ExpiresActive On
    ExpiresDefault "access plus 5 minutes"
    FileETag None
 </FilesMatch>
 </IfModule>

1 个答案:

答案 0 :(得分:1)

这样做:

RewriteEngine On

RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^admin/assets(?:/.*)?$ application/$0 [L]

RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^admin(?:/.*)?$ application/admin/index.php [L]

RewriteCond %{REQUEST_FILENAME} !^(.+)\.(css|js|xml|swf|flv|pdf)$
RewriteCond %{REQUEST_FILENAME} !^(.+)\.(jpg|jpeg|png|gif)$
RewriteCond %{REQUEST_FILENAME} !^(.+)\.(ttf|otf|eot|woff|svg)$
RewriteCond %{REQUEST_FILENAME} !cron.php
RewriteCond %{REQUEST_FILENAME} !/cache
RewriteCond %{REQUEST_FILENAME} !favicon.ico
RewriteCond %{REQUEST_FILENAME} !robots.txt
RewriteCond %{REQUEST_FILENAME} !ajax.php
RewriteCond %{REQUEST_FILENAME} !sitemap.xml
RewriteCond %{REQUEST_FILENAME} !/template/(.*)\.html
RewriteCond %{REQUEST_FILENAME} !/application/inc/OAuth(.*)\.php
RewriteRule ^(.+)/?([0-9]*)/?$ application/php/index.php [L]