Jump to content

Testing if a file exists - I dont know which param to use


adrianTNT

Recommended Posts

Hello.

I have the actual real directory structure like this:

my_files/101/

my_files/102/

 

and I want to rewrite to cleaner URL like this:

/101/

/102/

 

if there is an actual file index.html in the real folder my_files/101/index.html then I want that one shown at URL /101/ else I want it do display my script (generate_index.php).

I was trying something like:

 

RewriteCond %{REQUEST_FILENAME} -F

RewriteRule ^([0-9]+)/$ my_files/$1/index.html [QSA]

...

RewriteRule ^([0-9]+)/$ generate_index.php?$1[QSA]

 

But I guess REQUEST_FILENAME and -F is wrong way to test if index.html exists. Which param and string I have to test?

  • 2 weeks later...

The RewriteCond REQUEST_FILENAME checks if the file exists. If it does not exist, it applies the rules.

 

So basically,

 

RewriteCond %{REQUEST_FILENAME} !-f

 

Would 'tell' the server to check whether the index.html that is being requested is actually physically present on server. If it is not (the '!' is equal to 'not') the next line(s) of RewriteRules should be executed.

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.