forked from zionsg/zf2-project-htaccess
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path.htaccess
50 lines (46 loc) · 2.83 KB
/
.htaccess
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
##
# .htaccess for Zend Framework 2 (ZF2) projects
#
# This allows the ZF2 project to work whether it is placed in the web root or in a subfolder.
#
# In the original Zend Skeleton Application, .htaccess and index.php are placed in the public/ directory of the project
# which requires the setting up of a virtual host to point to the public/ directory.
# This is not feasible for projects on shared hosting with no access to the Apache config (typically httpd.conf)
# which means the project can only be accessed via http://example.com/project/public.
#
# .htaccess and index.php have been moved up to the main project folder and modified accordingly.
# Links to resources such as CSS in view scripts should now use $this->basePath('public/css/style.css')
# instead of $this->basePath('css/style.css').
#
# @see https://github.com/zendframework/ZendSkeletonApplication
# @link https://github.com/zionsg/zf2-project-htaccess for canonical source repository
# @author Zion Ng <[email protected]>
# @since 2015-02-23T15:30+08:00
# @version 2015-02-23T17:30+08:00
##
# Enable mod_rewrite
RewriteEngine On
# Store current folder as base path in BASE environment variable - to use, %{ENV:BASE}
# BASE = / if this .htaccess is in the web root, BASE = /subfolder/ if it is in a subfolder
# Using http://example.com/project/a/b as example with this .htaccess in /project/ (making /project/ the current folder)
# - request uri is /project/a/b
# - 1st group in RewriteRule is a/b (Apache removes the filesystem prefix including current folder hence no /project/)
# - the $1 in the RewriteCond is a backreference to the 1st group in the RewriteRule
# - the RewriteCond expands to "RewriteCond /project/a/b::a/b ^(/.+)(a/b)::a/b" giving /project/ for %1 in RewriteRule
RewriteCond %{REQUEST_URI}::$1 ^(/.*)(.*)::\2$
RewriteRule ^(.*) - [E=BASE:%1]
# Rewrite all queries to index.php (except itself and files inside the public/ directory of the project).
# The base path is prepended in RewriteRule to allow proper resolution of the index.php file whether Apache aliases
# are used to do mass virtual hosting or using a non-aliased environment, providing a safe, one-size fits all solution.
#
# Note that for "RewriteCond TestString CondPattern", server/environment variables cannot be used in CondPattern unless
# TestString is set to the special value "expr" in which case CondPattern will be treated as an ap_expr.
RewriteCond expr "! %{REQUEST_URI} -strcmatch '%{ENV:BASE}index.php'"
RewriteCond expr "! %{REQUEST_URI} -strcmatch '%{ENV:BASE}public/*'"
RewriteRule ^(.*)$ %{ENV:BASE}index.php [NC,L]
# If the above does not work, comment everything after RewriteEngine and uncomment the lines below
# RewriteCond %{REQUEST_FILENAME} -s [OR]
# RewriteCond %{REQUEST_FILENAME} -l [OR]
# RewriteCond %{REQUEST_FILENAME} -d
# RewriteRule ^.*$ - [NC,L]
# RewriteRule ^.*$ index.php [NC,L]