|
|
|
#1 |
|
Messages: n/a
Hébergeur: |
I posted this question almost two years ago, and had some excellent
replies but haven't been able to utilize them until now. I'm a real slacker, I know! :-) I'm trying to set up a site so that if someone tries to pull up a directory that doesn't exist, they'll be directed a PHP page with a GET variable. For instance, if they go to: www.mydomain.com/username (which doesn't exist) They'll see: www.mydomain.com/profile/view.php?id=username Here's the recipe I'm using in my .htaccess (supplied to me by a poster in this NG), uploaded to /home/mydomain/ (before the /www/): RewriteEngine on RewriteBase / RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME}/index.php !-f RewriteRule ^([a-zA-Z0-9|_]{4,10})/(.*) /www/profile/view.php?id=$1 This doesn't work (meaning, I still get a 404 error as if the .htaccess file didn't exist), and I'm trying to figure out why. So to start with, I need to make sure that I understand exactly what this recipe says. RewriteBase / # Sets the baseline at the root path. So if I upload it to the .htaccess file at /home/mydomain/, then the relative path of anything in this file will start at /home/mydomain/ RewriteCond %{REQUEST_FILENAME} !-d # Sets a condition: if DIRECTORY doesn't exist RewriteCond %{REQUEST_FILENAME}/index.php !-f # Same as above: if FILE index.php doesn't exist RewriteRule ^([a-zA-Z0-9|_]{4,10})/(.*) /www/profile/view.php?id=$1 # Here's where I'm a little lost. I understand the [a-zA-Z0-9|_] is checking something to make sure that it contains a letter, number, or _, but what is it checking? I'm assuming that it's reading everything after www.mydomain.com, but BEFORE the next / What does the {4,10} mean? And am I correct that, because of the RewriteBase that is set, this would rewrite to /home/mydomain/www/profile/view.php?id=$1? I also understand that the (.*) would read everything after the first /, and set that to $2, but I'm not using that right now (although I may in the future). If I'm correct about all of this, then I get back to the original question: why isn't it working? I tried a much simpler recipe for testing, but it had the same failure: RewriteEngine on RewriteRule ^/(.*) http://www.mydomain.com/profile/view.php?id=$1 Any ideas? TIA, Jason |
|
|
|
#2 |
|
Messages: n/a
Hébergeur: |
On Jan 2, 3:09am, Jason Carlton <jwcarl...@gmail.com> wrote:
> I posted this question almost two years ago, and had some excellent > replies but haven't been able to utilize them until now. I'm a real > slacker, I know! :-) > > I'm trying to set up a site so that if someone tries to pull up a > directory that doesn't exist, they'll be directed a PHP page with a > GET variable. For instance, if they go to: > > www.mydomain.com/username(which doesn't exist) > > They'll see: > > www.mydomain.com/profile/view.php?id=username > > Here's the recipe I'm using in my .htaccess (supplied to me by a > poster in this NG), uploaded to /home/mydomain/ (before the /www/): > > RewriteEngine on > RewriteBase / > RewriteCond %{REQUEST_FILENAME} !-f > RewriteCond %{REQUEST_FILENAME}/index.php !-f > RewriteRule ^([a-zA-Z0-9|_]{4,10})/(.*) /www/profile/view.php?id=$1 > > This doesn't work (meaning, I still get a 404 error as if > the .htaccess file didn't exist), and I'm trying to figure out why. So > to start with, I need to make sure that I understand exactly what this > recipe says. > > RewriteBase / > # Sets the baseline at the root path. So if I upload it to > the .htaccess file at /home/mydomain/, then the relative path of > anything in this file will start at /home/mydomain/ > > RewriteCond %{REQUEST_FILENAME} !-d > # Sets a condition: if DIRECTORY doesn't exist > > RewriteCond %{REQUEST_FILENAME}/index.php !-f > # Same as above: if FILE index.php doesn't exist > > RewriteRule ^([a-zA-Z0-9|_]{4,10})/(.*) /www/profile/view.php?id=$1 > # Here's where I'm a little lost. > > I understand the [a-zA-Z0-9|_] is checking something to make sure that > it contains a letter, number, or _, but what is it checking? I'm > assuming that it's reading everything afterwww.mydomain.com, but > BEFORE the next / > > What does the {4,10} mean? > > And am I correct that, because of the RewriteBase that is set, this > would rewrite to /home/mydomain/www/profile/view.php?id=$1? > > I also understand that the (.*) would read everything after the > first /, and set that to $2, but I'm not using that right now > (although I may in the future). > > If I'm correct about all of this, then I get back to the original > question: why isn't it working? I tried a much simpler recipe for > testing, but it had the same failure: > > RewriteEngine on > RewriteRule ^/(.*)http://www.mydomain.com/profile/view.php?id=$1 > > Any ideas? > > TIA, > > Jason As an addendum, I made a discovery today. This recipe works, although with problems: RewriteEngine On RewriteOptions MaxRedirects=5 # safety first RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d RewriteRule (.*)/(.*) http://www.mydomain.com/profile/view.php?id=$2 [L] Remember that the address I'm working with is www.mydomain.com/username. Here are the oddities: 1. Notice that I'm using (.*)/(.*), and then only using $2. I originally just used (.*) and $1, but it plugged in public_html/ username instead of just username. So, I had to add a second / in there to split this into 2. I haven't tested it, but I'm guessing that $1 would equal "public_html". 2. All of the tutorials said to use ^/(.*), but doing so gave me ISE errors. I was only able to correct that by removing the ^/. 3. This is my biggest complaint, really. If I use the flag [PT,L] to force a soft redirect, I get a 404 error. It only works with [L] or [L,R]. I really don't want it to redirect the browser like that, but I can't understand why I get an error. Any insight that you guys can give would be greatly appreciated! Jason |
|
![]() |
| Outils de la discussion | |
|
|