- 1 year ago 101
PHP Question

.htaccess rewrite in subdirectory not working under root directory with .htaccess

My domain points to root folder. In this folder I need to have .htaccess which will redirect to subfolder.

In the root folder I have this .htaccess:

RewriteEngine on
RewriteBase /
RewriteCond %{REQUEST_URI} !^/sub/folder/
RewriteCond %{HTTP_HOST} ^(www\.)?domain\.
RewriteRule ^(.*) /sub/folder/$1 [L]

In sub/folder/.htaccess I have this lines:

RewriteEngine on
RewriteBase /

ErrorDocument 404 /index.php?action=404

RewriteCond %{REQUEST_URI} ^/image/([^/]+)/(\d+)x(\d+)/([^/]+).(jpg|png)$
RewriteRule (.*) file.php?action=%1&code=%4&w=%2&h=%3 [B,L,QSA]

RewriteCond %{REQUEST_URI} ^/cscard_valid$
RewriteRule (.*) index.php?action=cscardvalid&ajax=true [L,QSA]

I don't known why redirects doesn't works. Can you help me please?

Answer Source

Get rid of the .htaccess in the subfolder then add rules to your root one like so:

RewriteRule ^image/([^/]+)/(\d+)x(\d+)/([^/]+).(jpg|png)$ sub/folder/file.php?action=$1&code=$4&w=$2&h=$3 [B,L,QSA]
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download