rocknbil

msg:4376013 | 4:29 pm on Oct 18, 2011 (gmt 0) |
I'll open this one, I've been spanked enough over it. :-) RewriteCond %{SCRIPT_FILENAME} !-f RewriteCond %{SCRIPT_FILENAME} !-d RewriteRule ^([a-z0-9]+)\/?$ profile.php?username=$1 |
| The effect is it searches the entire file system TWICE for the requested resource, first to see if it's a file, second to see if it's a directory, and is highly inefficient. Sadly, it's also the same bit of code used by almost every CMS or blog software out there. Please see post #4274745 in this thread [webmasterworld.com] for one way to fix this. It's so incredibly easy you'll wonder why no one else is using it.
|
gcan

msg:4376017 | 4:45 pm on Oct 18, 2011 (gmt 0) |
rocknbil, thank you for your answer. I tried this: RewriteRule ^([^.]+)$ /profile.php?username=$1 [L,QSA] Unfortunately, it doesn't work for me - it rewrites existing folders too :(
|
lucy24

msg:4376177 | 8:27 pm on Oct 18, 2011 (gmt 0) |
How many existing directories are there? Will anything other than user profiles ever have a query string? You can either nip them in the bud via a specific RewriteCond ending in !(realplace|otherrealplace|yetanother)/ or let the php script take them and then kick them right back after checking names. You probably know better than we do which version would place less strain on your system.
|
g1smd

msg:4376200 | 8:58 pm on Oct 18, 2011 (gmt 0) |
If you make sure that it doesn't rewrite requests that end in a slash then it will not rewrite folders. So [^.] should perhaps be [^/.] here. Make sure that all literal periods are escaped. You missed a few. Slashes do not need to be escaped. Add the [L] flag to every rule.
|
gcan

msg:4376501 | 11:42 am on Oct 19, 2011 (gmt 0) |
Lucy 24, I have about 40 directories. It's too much? No, only user profiles will have a query string (except other rewrite rules). G1smd, Yes, this works for me: RewriteRule ^([^/.]+)$ /profile.php?username=$1 [L,QSA] However, it causes the following problems. If I call an existing directory without ending slash, for example: [mydomain...] it rewrites in this way: [mydomain...] And of course [mydomain...] causes 404 error. Would like to find some solution so that everything works with and withoud ending slash.
|
lucy24

msg:4376685 | 6:10 pm on Oct 19, 2011 (gmt 0) |
Use example.com in all your examples to keep the Forums software from rewriting your links. Don't know about you, but this is what the rest of us see: If I call an existing directory without ending slash, for example: [mydomain...] it rewrites in this way: [mydomain...] And of course [mydomain...] causes 404 error. |
| Not very helpful eh ;)
|
gcan

msg:4376754 | 8:42 pm on Oct 19, 2011 (gmt 0) |
I am sorry. Forum script parsed links automatically and I can't edit my post. So, I post one more time: ===================================== Yes, this works for me:
RewriteRule ^([^/.]+)$ /profile.php?username=$1 [L,QSA] However, it causes the following problems. If I call an existing directory without ending slash, for example:
http://mydomain/existing-directory it rewrites in this way:
http://mydomain/existing-directory/?username=existing-directory. And of course
http://mydomain/username/ (with ending slash) causes 404 error.
|
g1smd

msg:4376756 | 8:50 pm on Oct 19, 2011 (gmt 0) |
Use example.com in this forum. See RFC 2606.
|
lucy24

msg:4376821 | 11:11 pm on Oct 19, 2011 (gmt 0) |
Now, wait a minute. If I call an existing directory without ending slash, for example: http://www.example.com/existing-directory it rewrites in this way: http://www.example.com/existing-directory/?username=existing-directory. |
| That would be wrong anyway, wouldn't it? You're ending up with "directoryname" in two places, and that can't possibly be what you intended. | RewriteRule ^([^/.]+)$ /profile.php?username=$1 [L,QSA] |
| Where's your RewriteCond that says "only do this if the query string does not already contain 'username=blahblah'"? And what happened to the "profile.php"? Poring over the sacred writings [httpd.apache.org] tells me that the directory-slash redirect is done by mod_dir, which probably executes after mod_rewrite but before mod_autoindex. (That's assuming reverse alphabetical order. If you are on shared hosting, all of this flies out the window.)
|
gcan

msg:4377300 | 8:49 pm on Oct 20, 2011 (gmt 0) |
URL rewriting is like a dark night for me :( Found a similar post where the same problem happends: [stackoverflow.com ] It looks that there are no other alternatives then: RewriteCond %{REQUEST_FILENAME} !-d
|
g1smd

msg:4377323 | 9:46 pm on Oct 20, 2011 (gmt 0) |
It depends what your're doing. Often RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /somepattern\ HTTP/ is useful. It ensures the pointer being tested was set as a result of an external request and not from a previous rewrite.
|
|