PHWinfo banniere

Titres
PORTAIL ANNUAIRE ARTICLES COMPARATEUR HÉBERGEURS DEVIS FORUMS RÉDUCTEUR D'URL
Précédent   PHWinfo > Autres forums > Forum Programmation & Conception > alt.www.webmaster > Working with RewriteEngine
S'inscrire FAQ Membres Recherche Messages du jour Marquer les forums comme lus
Working with RewriteEngine

Réponse
 
LinkBack Outils de la discussion
Vieux 02/01/2008, 08h09   #1
Jason Carlton
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Working with RewriteEngine

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
  Réponse avec citation
Vieux 03/01/2008, 03h20   #2
Jason Carlton
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: Working with RewriteEngine

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
  Réponse avec citation
Réponse


Outils de la discussion

Règles de messages
Vous ne pouvez pas créer de nouvelles discussions
Vous ne pouvez pas envoyer des réponses
Vous ne pouvez pas envoyer des pièces jointes
Vous ne pouvez pas modifier vos messages

Les balises BB sont activées : oui
Les smileys sont activés : oui
La balise [IMG] est activée : oui
Le code HTML peut être employé : non
Trackbacks are oui
Pingbacks are oui
Refbacks are oui


Fuseau horaire GMT +1. Il est actuellement 09h58.


Édité par : vBulletin® version 3.7.3
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.2.0 RC5 Tous droits réservés.
Version française #16 par l'association vBulletin francophone
PHWinfo est un site Éducation Sans Frontières ©2000-2008
Ad Management by RedTyger
©Tous droits réservés par les parties respectives
Page generated in 0,12819 seconds with 10 queries