|
Posted by d on 04/01/06 22:06
"Stephen Kay" <sk@karma-lab.nospam.com> wrote in message
news:C0521A79.5B343%sk@karma-lab.nospam.com...
> in article C04E2935.5AC82%sk@karma-lab.nospam.com, Stephen Kay at
> sk@karma-lab.nospam.com wrote on 3/27/06 11:46 PM:
>
>>> What server are you using?
>>> If you are using apache then you can use RewriteRule ... It will do
>>> exactly
>>> what you are after.
>>>
>>> RewriteRule ^([^/]+)/([^/]+).html$ /dopage.php?p=$1 [L]
>>>
>>> Then you can worry about what dopage.php actually does.
>
> Hi, I've been working on this, and it's working.
>
> But presently, I'm doing this:
>
> RewriteRule ^([^/]+)/([^/]+)/([^/]+)/([^/]+).html$
> /dopage3.php?p=$1/$2/$3/$4.html
> RewriteRule ^([^/]+)/([^/]+)/([^/]+).html$ /dopage3.php?p=$1/$2/$3.html
> RewriteRule ^([^/]+)/([^/]+).html$ /dopage3.php?p=$1/$2.html
> RewriteRule ^([^/]+).html$ /dopage3.php?p=$1.html [L]
>
>
> This looks really stupid to me, but I haven't come on a better syntax.
>
> In other words, it needs the first line to redirect something like:
>
> folder1/folder2/folder3/file.html to
> /dopage.php?p= folder1/folder2/folder3/file.html
>
> and then the next line to do
>
> folder1/folder2/file.html to
> /dopage.php?p= folder1/folder2/file.html
>
> ..etc., depending on how many layers down the html is nested.
>
> Is there a simpler way to write this that only takes one line? I would
> have
> thought something like this (based on my limited understanding), but it
> doesn't seem to work exactly the same:
>
> RewriteRule ^([*]).html$ /dopage3.php?p=$1.html [L]
You can do this:
RewriteCond /var/www/htdocs/static%{REQUEST_URI} -f
RewriteRule (.*) /static$1 [L]
RewriteRule .* /dostuff.php [NS,L]
and every file that exists in the static/ subdirectory will be served as if
it was in the root, and all requests to files that do not exist in there are
sent to the dostuff.php. You don't have to worry about breaking the URI
apart in the rewrite configuring, as you can explode()
$_SERVER["REQUEST_URI"] in dostuff.php to see what exactly was requested.
If you don't want to have your static content in a static subdirectory, you
can do this:
RewriteCond /var/www/htdocs%{REQUEST_URI} !-f
RewriteRule .* /dostuff.php [NS,L]
hope that helps!
dave
>
>
> --
> Stephen Kay
> Karma-Lab sk@karma-lab.NOSPAM.com
> ^^^^^^^
>
>
[Back to original message]
|