PHWinfo banniere

Titres
PORTAIL ANNUAIRE ARTICLES COMPARATEUR HÉBERGEURS DEVIS FORUMS RÉDUCTEUR D'URL
Précédent   PHWinfo > Forums Hébergement > Forum Serveur - Sécurité et techniques > alt.apache.configuration > I've got something set wrong-- with mod_rewrite in .htaccess
S'inscrire FAQ Membres Recherche Messages du jour Marquer les forums comme lus
alt.apache.configuration Apache web server configuration issues.

I've got something set wrong-- with mod_rewrite in .htaccess

Réponse
 
LinkBack Outils de la discussion
Vieux 06/05/2007, 21h49   #1
Acrobatic
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut I've got something set wrong-- with mod_rewrite in .htaccess

Hello

I'm new with mod_rewrite, and I've gone through a lot of examples and
still can't get anything to work. What I'm trying to is do a
conditional redirect like,

http://www.mysite.com/james redirects to http://www.mysite.com/userpages.php?user=james

My userpages.php will take the user variable and look for user
"james." It will then load dynamic content based on that user. If
there is no such username, I'll assume the user wants whatever page
they typed, so I'd redirect them to "index.php", or whatever page they
wanted. I just want to have a decider page that determines where the
user should go.

I think I want every page in the root of my server to get redirected
to a decider page (if this isn't the best solution your suggestions
are welcome!)

There's probably something simple I'm missing, but it's just not
working for me. In my httpd.conf file I have

LoadModule rewrite_module libexec/httpd/mod_rewrite.so

and

AddModule mod_rewrite.c

And, in the root of my web directory, I have an .htacess file that
says:

RewriteEngine On
RewriteRule ^ /path/to/my/webserver/deciderpage.php

It doesn't seem to work. If I type in my url, www.mysite.com (or even
www.mysite.com/james) it shows the index page and not the decider
page.

I hope that was clear--and thanks for any . I'm stumped

-Jeff

  Réponse avec citation
Vieux 07/05/2007, 00h19   #2
shimmyshack
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: I've got something set wrong-- with mod_rewrite in .htaccess

On May 6, 9:49 pm, Acrobatic <jbn...@gmail.com> wrote:
> Hello
>
> I'm new with mod_rewrite, and I've gone through a lot of examples and
> still can't get anything to work. What I'm trying to is do a
> conditional redirect like,
>
> http://www.mysite.com/jamesredirects tohttp://www.mysite.com/userpages.php?user=james
>
> My userpages.php will take the user variable and look for user
> "james." It will then load dynamic content based on that user. If
> there is no such username, I'll assume the user wants whatever page
> they typed, so I'd redirect them to "index.php", or whatever page they
> wanted. I just want to have a decider page that determines where the
> user should go.
>
> I think I want every page in the root of my server to get redirected
> to a decider page (if this isn't the best solution your suggestions
> are welcome!)
>
> There's probably something simple I'm missing, but it's just not
> working for me. In my httpd.conf file I have
>
> LoadModule rewrite_module libexec/httpd/mod_rewrite.so
>
> and
>
> AddModule mod_rewrite.c
>
> And, in the root of my web directory, I have an .htacess file that
> says:
>
> RewriteEngine On
> RewriteRule ^ /path/to/my/webserver/deciderpage.php
>
> It doesn't seem to work. If I type in my url,www.mysite.com(or evenwww.mysite.com/james) it shows the index page and not the decider
> page.
>
> I hope that was clear--and thanks for any . I'm stumped
>
> -Jeff


firstly was .htacess a typo, (it's usually .htaccess)
secondly to use the online apache documention simple google
"apache 2 docs rewrite examples"
although it might take some reading, there are lots of examples which
cover your kind of issue there.

when you say "redirects to" I am assuming you mean "rewrites to" -
that you wish the url to stay the same but the page returned to be
http://www.mysite.com/userpages.php?user=james
if you wish to redirect you do not need the rewrite engine at all,
merely a redirect line.

you might like to uncomment the rewritebase line the following doesnt
work
ReWriteEngine On
#ReWriteBase /
ReWriteRule ^/?james/?$ /userpages.php?user=james

that's it. hard coded this means the start of the URI must be an
optional / followed by the word james followed by another optional /
which should be the last character, this gets rewritten to /
userpages.php?user=james

As previously said, if you just need a browser redirect use this by
itself, no need for rewrites, you do need mod_alias for the redirect
though.
RedirectPermanent ^/?james/?$ http://www.mysite.com/userpages.php?user=james

However as you seem to have access to the httpd.conf, I recommend
turning htaccess files off completely server wise using
AllowOverride None
..htaccess are less secure (in case of server misconfig they might be
downloaded revealing info on the setup)
Instead for the servername (vhost) you are talking about encase your
rewrites or redirect in a directory block
<Directory /path/to/root/of/www.mysite.com/>
#put rewrites or redirect here
#no need for rewritebase here.
</Directory>

  Réponse avec citation
Vieux 07/05/2007, 14h56   #3
Acrobatic
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: I've got something set wrong-- with mod_rewrite in .htaccess

shimmyshack said

> ReWriteEngine On
> #ReWriteBase /
> ReWriteRule ^/?james/?$ /userpages.php?user=james


That did the trick. Things weren't working right in my .htaccess file
because AllowOverride was set to None in my httpd.conf file. I did
want to do rewrites, not redirects, thank you for clearing up the
difference between the two for me.

Thanks again for the info--that was a big
J




  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 20h56.


Édité par : vBulletin® version 3.7.2
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
Ad Management by RedTyger
©Tous droits réservés par les parties respectives
Page generated in 0,11186 seconds with 11 queries