views:

127

answers:

2

I am trying to design a small site where most of (95%) of site assets will be passed through home sort of PHP script, and the remaining 5% are being hosted from a subdomain (background images, logos, etc. What I would like is that whenever a page is called, say www.example.com/blog/My_trip_to_the_andes the page that would be called is htdocs/nexus.php and that script would be able to discover what URI was requested. From that URI the script will determine what the user is asking for and generate it. As the redirects happen the headers need to be maintained, so the script receives any POST data or COOKIE data.

I believe that I can accomplish this with an .htaccess in the site root directory. But I have little to no experience with .htaccess and the documentation doesn't seem to speak to this.

Is this even a good idea? I want every page request to go through a script so I can log, do some 404 tracking and redirects, gate keep cross site requests for resources, and stuff I can't even think about yet.

+1  A: 

.htaccess;-

<IfModule mod_rewrite.c>
RewriteEngine On

RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /htdocs/nexus.php [L]
</IfModule>

And the filename that was actually called should be available as $_SERVER['REQUEST_URI']

Mez
But $_SERVER['REQUEST_URI'] does not include the entirety of the requested uri.
tvanover
A: 

Since your static resources resident on a different domain, you could send all requests to your nexus.php file with this mod_rewrite rule:

RewriteEngine on
RewriteRule !^nexus\.php$ nexus.php [L]

The original requested URL is then available in $_SERVER['REQUEST_URI'] (note that this also contains the URL query and not just the URL path).

But if you have other files that you want to allow access to, you can exclude them with this additional condition attached to the previous rule:

RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule !^nexus\.php$ nexus.php [L]

Now only requests that can not be directly mapped onto existing files (!-f) are rewritten to nexus.php.

Gumbo