clusterBuddy clusterBuddy - 2 months ago 10
PHP Question

.htaccess rule error for redirecting from a homepage form submit

I have a top level domain that has a form in it, when I submit the form I get the error that it's no found (it's looking for it in the wrong place.)

the original locations of the index is here:

www.tld.com/tld/src/index.html

the php file that handles the form into the DB is here:
www.tld.com/tld/lib/phpfile.php

I am using this .htaccess rule to send my homepage to www.tld.com:

RewriteEngine On
RewriteCond %{REQUEST_URI} !^/tld/src/
RewriteRule ^(.*) /tld/src/$1 [L]


Obviously, the redirection is an error:
The requested URL /tld/src/lib/phpfile.php was not found on this server.
since the file exists in
www.tld.com/tld/lib/phpfile.php



My current and only settings except for the above are:


Options All -Indexes


<Files .htaccess>
deny from all
</Files>



And that's it.


I am new to .htaccess apache rulesets and I have no idea how to fix this. Thank you.

Answer

You can tweak your exception condition:

RewriteEngine On
RewriteBase /tld/

RewriteCond %{REQUEST_URI} !/(src|lib)/ [NC]
RewriteRule ^(.*) src/$1 [L]

Above condition will skip any request that starts with /tld/lib/ or /tld/src/ thus allowing your form to be routed to correct php file in /tld/lib/ directory.