Forum Moderators: phranque

Message Too Old, No Replies

htaccess real and virtual files in folder?

Mixing real and virtual files in a folder with htaccess. Possible?

         

blueeyebrit

10:20 am on Jun 28, 2011 (gmt 0)

10+ Year Member



Hi all - I'm discovering today that I'm more of a newbie at htaccess then I had thought, thus I was wondering if anyone might be able to offer some pointers as to where the answer might lie.

In essence I'm trying to create an .htaccess set of rules that say
* If file in directory exists, run it
* If file in directory doesn't exist, default to the CMS (in this case Wordpress).

I've tried both of the following (along with other similar variations that I shan't flood the page with) in the root .htaccess without joy

RewriteRule ^folder/index2.\php$ - [NC,L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]


RewriteCond %{REQUEST_URI} ^/folder/index2\.php [NC]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]


From that I can say that the real file is /folder/index2.php and what I'd like to achieve is when it's not that file being called up, Wordpress does in its place ('folder' is set up in a category in Wordpress - if the folder doesn't exist it works fine, when it is created wordpress 404s when attempting to generate a CMS page).

Any suggestions for where I might be going wrong in this quest?

Thanks :)

lucy24

7:13 pm on Jun 28, 2011 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



RewriteRule ^folder/index2.\php$ - [NC,L]

Is this rule intended to do anything, or is it just meant to exempt requests in this form from being tested against any of the other rules? By "both of the following" did you mean that your htaccess will contain either the first block of 4 lines or the second block, but not both concurrently?

I love the words "without joy" but you gotta spell out exactly what form your joylessness takes. That is, does nothing happen at all (it carries on as if this part of your htaccess didn't exist) or does the wrong thing happen?

Are you basically trying to send all 404s to your index page instead of dead-ending at your 404 page? That's pretty straightforward, so long as you include a R=404. And, of course, make sure all your internal links-- and any others that are under your control-- point directly to a real page.

blueeyebrit

1:24 am on Jun 29, 2011 (gmt 0)

10+ Year Member



Thanks for your reply :)

What I'm hoping to do is create a step through scenario:

So there is a real file at /folder/index2.php

When /folder/index2.php is called up, serve it
Elseif anything else is called up in /folder/ default to /index.php which is the CMS

With the two examples I've provided (based on my working knowledge of .htaccess / httpd.conf) /folder/index2.php is served fine, but any other calls to /folder/ result in the server issuing a 404 as opposed to defaulting back to /index.php to call on the CMS to generate a virtual page.

blueeyebrit

1:47 am on Jun 29, 2011 (gmt 0)

10+ Year Member



Further to that explanation.

A virtual URL might look like

/folder/{NAME}-[UNIQUE ID}.html

That page generates fine through Wordpress provided that /folder/ doesn't actually exist

lucy24

3:33 am on Jun 29, 2011 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



Y'know what? I think this may actually be a WordPress question. Is it possible that /folder/ isn't supposed to exist, and WP throws fits if it finds a real one squatting in its virtual territory? Would it be a copout to move your real file index2 into some other directory that WP has no interest in? And give it a standard name while you're at it.