|
|
|
|
||||||
| alt.apache.configuration Apache web server configuration issues. |
![]() |
|
|
LinkBack | Outils de la discussion |
|
|
#1 |
|
Messages: n/a
Hébergeur: |
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 |
|
|
|
#2 |
|
Messages: n/a
Hébergeur: |
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> |
|
|
|
#3 |
|
Messages: n/a
Hébergeur: |
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 |
|
![]() |
| Outils de la discussion | |
|
|