This is a discussion on mod_rewrite/alias confusion within the Apache Web Server forums, part of the Web Server and Related Forums category; Two things: I have an executable web app that dynamically handles all the pages for my site. I don't ...
|
|||||||
| FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read |
|
|||
|
Two things:
I have an executable web app that dynamically handles all the pages for my site. I don't thoroughly understand the difference between using mod_rewrite and alias to direct all requests for a page to this app. I'm pretty sure I should use mod_rewrite but would like someone to verify that and, hopefully, explain why alias is not what I want. I've gone through 27 books and 32 web sites, along with 101 variations of mod_rewrite and, on variation number 37 from book 3, I think, I can get http://www.mysite.com/ to properly work with the app; but only that index page and nothing else, such as mysite.com/page1. Obviously, I just don't get it. So: 1) Is mod_rewrite what I want to do? 2) Can someone show me how to set it up so all page requests go to my web app alone? (Minus images, stylesheets, etc.) |
|
|||
|
So this is what I have so far and it partly does what I want:
RewriteEngine on RewriteRule ^/?(.*)$ cgi-bin/test [L] I don't think that's what I want to run with because I think a problem could come up with it matching everything, including impossibly long or obscure matches. Another problem is that it also matches image extensions, css stylesheets, javascripts and anything else I don't need to serve dynamically. |
|
|||
|
On May 4, 2:09 pm, drhowarddrfine <robbel...@gmail.com> wrote:
> So this is what I have so far and it partly does what I want: > > RewriteEngine on > RewriteRule ^/?(.*)$ cgi-bin/test [L] > > I don't think that's what I want to run with because I think a problem > could come up with it matching everything, including impossibly long > or obscure matches. Another problem is that it also matches image > extensions, css stylesheets, javascripts and anything else I don't > need to serve dynamically. I forgot to add that I changed the rewrite rule to this: ^([a-zA-Z_]+)/([a-zA-Z_]+)/([a-zA-Z_]+)$ cgi-bin/test [L] But it doesn't work at all. |
|
|||
|
drhowarddrfine schreef:
> So this is what I have so far and it partly does what I want: > > RewriteEngine on > RewriteRule ^/?(.*)$ cgi-bin/test [L] > > I don't think that's what I want to run with because I think a problem > could come up with it matching everything, including impossibly long > or obscure matches. Another problem is that it also matches image > extensions, css stylesheets, javascripts and anything else I don't > need to serve dynamically. you should read http://httpd.apache.org/docs/2.2/mod/mod_rewrite.html and look at RewriteCond this way you can exclude the things you will not rewrite.. -- Luuk |
|
|||
|
"drhowarddrfine" <robbelics@gmail.com> schreef in bericht
news:817e5f36-1b8a-4ed2-b90e-89c88c1bd434@b1g2000hsg.googlegroups.com... > On May 4, 2:09 pm, drhowarddrfine <robbel...@gmail.com> wrote: A small note on the subject: mod_rewrite modifies the mapping of an url to the filesystem to a lot wider extend then mod_alias. The latter only unconditionally changes the mapping for a complete folder. >> So this is what I have so far and it partly does what I want: Not sure whether you have full control over Apache or just only are twisting it via .htaccess. Unfortunately the two have slightly different syntax and behaviour... Assuming you are using a .htaccess at the root of the site. >> RewriteEngine on >> RewriteRule ^/?(.*)$ cgi-bin/test [L] >> >> I don't think that's what I want to run with because I think a problem >> could come up with it matching everything, including impossibly long >> or obscure matches. Another problem is that it also matches image >> extensions, css stylesheets, javascripts and anything else I don't >> need to serve dynamically. Be more selective, example given only do html by: RewriteEngine on RewriteRule (.*\.html)$ cgi-bin/test [NC,L] Note the NC for no(t) case-sensitive matching. You might consider testing presence of static content before giving dynamic response: RewriteEngine on RewriteCond %{ REQUEST_FILENAME} !-f RewriteRule (.*\.html)$ cgi-bin/test [NC,L] (Might be handy for error documents ... ) Running .htaccess based rewrites has a performance penalty. To minimize the effect, consider setting up folders like \images \scripts \test The latter will hold hardly no files, but at least a .htaccess reading like RewriteEngine on RewriteBase / RewriteCond %{ REQUEST_FILENAME} !-f RewriteRule (.*\.html)$ cgi-bin/test [NC,L] > I forgot to add that I changed the rewrite rule to this: > ^([a-zA-Z_]+)/([a-zA-Z_]+)/([a-zA-Z_]+)$ cgi-bin/test [NC,L] > > But it doesn't work at all. It does work, but the way you want it ;-) It only matches a path like /a_B/bC/C_d, but NOT /a_B/bC/C_d.html. Notice all dynamic urls MUST BE exactly 2 levels below the site's root. HansH -- http://httpd.apache.org/docs/2.2/rewrite/ "Despite the tons of examples and docs, mod_rewrite is voodoo. Damned cool voodoo, but still voodoo." |
|
|||
|
On May 4, 2:20 pm, Luuk <L...@invalid.lan> wrote:
> drhowarddrfine schreef: > > > So this is what I have so far and it partly does what I want: > > > RewriteEngine on > > RewriteRule ^/?(.*)$ cgi-bin/test [L] > > > I don't think that's what I want to run with because I think a problem > > could come up with it matching everything, including impossibly long > > or obscure matches. Another problem is that it also matches image > > extensions, css stylesheets, javascripts and anything else I don't > > need to serve dynamically. > > you should readhttp://httpd.apache.org/docs/2.2/mod/mod_rewrite.html > and look at RewriteCond > > this way you can exclude the things you will not rewrite.. > > -- > Luuk Read it over and over and over again. I think my problem is I keep messing up with the regex. It's quiet today so I'm better able to concentrate and may have found a way to get this work but would be interested in what other people have to say: RewriteRule ^/?([a-z/-]+)$ cgi-bin/test [L] |
|
|||
|
On May 4, 3:28 pm, "HansH" <ha...@invalid.invalid> wrote:
> "drhowarddrfine" <robbel...@gmail.com> schreef in berichtnews:817e5f36-1b8a-4ed2-b90e-89c88c1bd434@b1g2000hsg.googlegroups.com...> On May 4, 2:09 pm, drhowarddrfine <robbel...@gmail.com> wrote: > > A small note on the subject: > mod_rewrite modifies the mapping of an url to the filesystem to a lot wider > extend then mod_alias. The latter only unconditionally changes the mapping > for a complete folder. > Ah, yes. I recall reading that. Thank you. > Not sure whether you have full control over Apache or just only are twisting > it via .htaccess. Yes. htaccess only. Forgot to mention that. Also Apache version 1.3 > > Be more selective, example given only do html by: > RewriteEngine on > RewriteRule (.*\.html)$ cgi-bin/test [NC,L] > > Note the NC for no(t) case-sensitive matching. > There are no extensions to any of the pages themselves. > > Running .htaccess based rewrites has a performance penalty. > To minimize the effect, consider setting up folders like > \images > \scripts > \test > Doing that, yes. Thanks for all that, Hans. Glad to see I was doing some things right. |
|
|||
|
"drhowarddrfine" <robbelics@gmail.com> schreef in bericht
news:0e88e188-f2aa-4377-b1af-824c52f24f44@m3g2000hsc.googlegroups.com... > Yes. htaccess only. Forgot to mention that. Also Apache version 1.3 > >> Be more selective, example given only do html by: >> RewriteEngine on >> RewriteRule (.*\.html)$ cgi-bin/test [NC,L] >> Note the NC for no(t) case-sensitive matching. > There are no extensions to any of the pages themselves. Just wondering what Google might think of those ... .... anyway consider excluding anything with a dot: RewriteRule ^([^\.]+)$ cgi-bin/test [NC,L] HansH |
| Thread Tools | |
| Display Modes | |
|
|