Mod_rewrite, I want to determine if a file exists in another directory and

I want to specify a subdirectory file if one exists.

I currently have a .htaccess file in the feed:

RewriteCond my_sub_dir/%{REQUEST_FILENAME} -d RewriteRule ^.*$ my_sub_dir/%{REQUEST_FILENAME} [L] 

Basically, I want http://example.com/js/application.js to point to my_sub_dir / js / application.js if it exists

+1
apache mod-rewrite
source share
1 answer

-d checks if the given path is valid for an existing directory. If you want to test regular files, use -f . But you also need to provide an absolute path to the file system. So try the following:

 RewriteCond %{DOCUMENT_ROOT}/my_sub_dir%{REQUEST_URI} -f RewriteRule ^ %{DOCUMENT_ROOT}/my_sub_dir%{REQUEST_URI} [L] 
0
source share

All Articles