I have a link on the main page to
www.example.com/test
I have a page in a pages directory, called test.php
Here’s what my .htaccess looks like:
RewriteBase /
RewriteEngine on
RewriteCond pages/%{REQUEST_FILENAME}.php -f [NC]
RewriteRule ^(.*?)$ pages/$1.php
Now, I can get it to work with RewriteRule ^test$ pages/test.php, but as soon as I put in the regex, it won’t work. Also, the RewriteCond rule doesn’t seem to work either. Any solutions you can think of? I have tried adding Options +FollowSymlinks -MultiViews but it didn’t work.
update
If I add a test.php to the main directory, then change RewriteCond pages/%{REQUEST_FILENAME}.php -f [NC] to RewriteCond %{REQUEST_FILENAME}.php -f [NC] then it works; so that is where the problem is.
I can’t figure out how to check if the file exists in the pages directory.
REQUEST_FILENAME is the full server path. So if your document root path is
/home/website/public/you are trying to check ifpages/home/website/public/test.phpexists, which of course it doesn’t.Here are the rules you want.