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?

Link to comment
Share on other sites

  • 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.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.