wooper clooper
wooper clooper

Reputation: 87

htaccess combine folder with alias

I have 3 folders in a sub directory of my root directory i would like to combine.

My site map:

mywebsite.com
mywebsite.com/test/
mywebsite.com/test/one/
mywebsite.com/test/one/one.php
mywebsite.com/test/two/two.php
mywebsite.com/test/three/three.php

I would like to access:

mywebsite.com/test/one/one.php
mywebsite.com/test/two/two.php
mywebsite.com/test/three/three.php

by using:

mywebsite.com/test/combine/one.php
mywebsite.com/test/combine/two.php
mywebsite.com/test/combine/three.php

Solution...

RewriteEngine On

RewriteRule .* - [E=directory:/test/]
RewriteRule .* - [E=one:one/]
RewriteRule .* - [E=two:two/]
RewriteRule .* - [E=three:three/]

RewriteCond %{REQUEST_FILENAME}  !-f
RewriteCond %{REQUEST_FILENAME}  !-d
RewriteCond %{DOCUMENT_ROOT}%{ENV:directory}%{ENV:one}$1 -f     [OR]
RewriteCond %{DOCUMENT_ROOT}%{ENV:directory}%{ENV:one}$1 -d
RewriteRule ^combine/(.*)$  %{ENV:directory}%{ENV:one}$1    [L]


RewriteCond %{REQUEST_FILENAME}  !-f
RewriteCond %{REQUEST_FILENAME}  !-d
RewriteCond %{DOCUMENT_ROOT}%{ENV:directory}%{ENV:two}$1 -f     [OR]
RewriteCond %{DOCUMENT_ROOT}%{ENV:directory}%{ENV:two}$1 -d
RewriteRule ^combine/(.*)$  %{ENV:directory}%{ENV:two}$1    [L]


RewriteCond %{REQUEST_FILENAME}  !-f
RewriteCond %{REQUEST_FILENAME}  !-d
RewriteCond %{DOCUMENT_ROOT}%{ENV:directory}%{ENV:three}$1 -f   [OR]
RewriteCond %{DOCUMENT_ROOT}%{ENV:directory}%{ENV:three}$1 -d
RewriteRule ^combine/(.*)$  %{ENV:directory}%{ENV:three}$1  [L]

This works but i would like to minimize the script

Upvotes: 1

Views: 83

Answers (1)

Panama Jack
Panama Jack

Reputation: 24478

Try it this way for consolidation, if you simplify it.

RewriteEngine On

RewriteCond %{REQUEST_FILENAME}  -f [OR] 
RewriteCond %{REQUEST_FILENAME}  -d
RewriteRule ^ - [L]

RewriteCond %{DOCUMENT_ROOT}/test/$1/$1.php -f 
RewriteRule ^combine/(.*)(?:\.php)$  /test/$1/$1.php  [L]

Upvotes: 1

Related Questions