Apache Development
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me
Go Back   Dev Shed ForumsSystem AdministrationApache Development

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
Stop making mediocre tutorials.The best tutorials are video! Camtasia Studio makes it easy to create engaging, buzz-building screen videos at any size, in any popular format. Download the free trial!
  #1  
Old July 20th, 2001, 09:00 AM
jizzaz jizzaz is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jul 2001
Posts: 13 jizzaz User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 36 m 24 sec
Reputation Power: 0
Talking mod_rewrite offline / on http://localhost?

Hi @all
I've been reading most of the threads on mod_rewrite in this forum specificially the ones with "freebsd" and "forefront". Although I think I understand the basic syntax. I'm not getting any results period. Is there any way to find out if it is working at all?

I compiled Apache with --enable-module=rewrite. Under PHPinfo it says mod_rewrite is installed too.

I'm thinking it has to do with me working the whole thing offline (on a linuxbox) or that mod_rewrite is not processing anything. I tried RewriteLog and I don't get any output.

Thanks for your help

Reply With Quote
  #2  
Old July 21st, 2001, 06:59 AM
freebsd freebsd is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jan 2001
Posts: 5 freebsd User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
What you mean by offline? Apache daemon not running? Or accessing http://localhost or http://192.168.0.1 in your local network or from within your Apache box?

mod_rewrite should work with http://localhost. If you had a problem, please post your code and be more specific, since I have no clue what your problem was.

Reply With Quote
  #3  
Old July 21st, 2001, 08:43 AM
jizzaz jizzaz is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jul 2001
Posts: 13 jizzaz User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 36 m 24 sec
Reputation Power: 0
Hi, freebsd

By offline I meant that I'm not really on a http://www.mysite.com but http://localhost or http://localhost.linuxbox on my laptop. The Apache daemon is running and php works great.

Every Code I've tried does not seem to work. My current .htaccess file located in /usr/local/apache/htdocs/ reads:
***********************************************************************
RewriteEngine on
RewriteRule ^(.+)/$ index.php?id=$1 [T=application/x-httpd-php]
***********************************************************************

index.php:
<?php
echo $id;
?>

If I type http://localhost.linuxbox/index.php?id=3
I get "3" on the resulting page.

If I type http://localhost.linuxbox/?id=3
I get "3" on the resulting page.

If I type http://localhost.linuxbox/3/
I get a 404 error

If I type http://localhost.linuxbox/3
I get a 404 error

I'm running Mozilla 0.9.2 on Slackware 8.0 with Apache 1.3.19 compiled from sources.

I'm thinking it has to do mod_rewrite not being configured right, because I don't get any messages when using :
***********************
RewriteLog /home/alex/rewrite.log
RewriteLogLevel 9
***********************

and I've tried almost every combination from your posts with forefront.

Reply With Quote
  #4  
Old July 21st, 2001, 09:21 AM
freebsd freebsd is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jan 2001
Posts: 5 freebsd User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Try this(untested):

RewriteEngine on
RewriteCond %{REQUEST_URI} ^/index\.php.*
RewriteRule ^(.+) - [L]
RewriteCond %{REQUEST_URI} ^/(.*)$
RewriteRule ^/([A-Za-z0-9]+)/?$ index.php?id=$1 [T=application/x-httpd-php,L]
RewriteRule ^(.+) index.php?id=$1 [T=application/x-httpd-php,L]

This intends to work just one level deep, no more no less.
http://localhost.linuxbox/3/1/ won't work.

Not sure what you trying to do exactly, should people type http://localhost.linuxbox/index.php?id=3 at all? If not, you should consider removing index.php from DirectoryIndex and for a request of ^$, redirect to http://localhost.linuxbox/index/

>> because I don't get any messages when using

You also need RewriteEngine on

Reply With Quote
  #5  
Old July 21st, 2001, 11:13 AM
jizzaz jizzaz is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jul 2001
Posts: 13 jizzaz User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 36 m 24 sec
Reputation Power: 0
Nope,
I get the 404 Error:
requested URL /3 was not found

I tried this with index.php in DirectoryIndex and without it. Same result

Here is what I'm trying to do:

1. Everything from index.php:

The only script will be index.php.
Using PHP I will search a database based on variables. Ex.
http://linuxbox.localhost/Sports/Shoes/Nike/12355453

2. No directories:

Only variables after http://linuxbox.localhost

3. No visible script name:

The user should never see index.php

4. All links on the web site should also be in the form:

http://linuxbox.localhost/ProductGroup/Section/Category
Links should adhere to rules 1-3.

Basicially the user should never see a URL like:
http://linuxbox.localhost/index.php...orts&sect=Shoes
in the locationbar or statusbar.

I feel badly because you basically covered all this in your postings with "forefront". And I'm trying to do the same thing.
Since I tried all the code from those postings and none of it worked. I was aiming for something really simple in an attempt to get any kind of rewrite result. Thus far I haven't seen the mod_rewrite module do anykind of rewriting

I really think my problem has nothing to do with the syntax in the .htaccess file. Just to cover all bases, here is what I do when I change the contents of the .htaccess of httpd.conf files:
Restart Apache, clear cache,history in Mozilla
I even chmod 777 .htaccess.

Reply With Quote
  #6  
Old July 22nd, 2001, 03:52 AM
pippo's Avatar
pippo pippo is offline
A PAtCHy sErver
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jun 2001
Location: Italy
Posts: 410 pippo User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 8
I do not know If you already did it,
but instead of putting your rewrite rules inside .htaccess,
you could put them inside httpd.conf.
If they works OK, then the problem could be that .htaccess is not recognized properly.

Just a suggestion.

Reply With Quote
  #7  
Old July 22nd, 2001, 04:56 AM
freebsd freebsd is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jan 2001
Posts: 5 freebsd User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
>> requested URL /3 was not found

Sorry my mistake for not having it tested. The line:
RewriteRule ^/([A-Za-z0-9]+)/?$ index.php?id=$1 [T=application/x-httpd-php,L]

The 1st / was the problem.

>> Here is what I'm trying to do

That's what I wanted to know in the first place.

1) Give index.php highest priority for DirectoryIndex
2) Here is a revision (tested):
# enabling mod_rewrite
RewriteEngine on
# for request of http://linux.localhost/ or http://linux.localhost or http://linux.localhost/index.php
RewriteCond %{REQUEST_URI} ^/index\.php.*
# do not continue and last it
RewriteRule ^(.+) - [L]
# if request is anything else
RewriteCond %{REQUEST_URI} ^/(.*)$
# check and see if the pattern matches
# http://linux.localhost/foo -> matches and $QUERY_STRING returns group=foo&section=category=
# http://linux.localhost/foo/bar -> matches and $QUERY_STRING returns group=foo&section=bar&category=
# http://linux.localhost/foo/bar/ha -> matches and $QUERY_STRING returns group=foo&section=bar&category=ha
RewriteRule ^([A-Za-z0-9]+)/?([A-Za-z0-9]*)/?([A-Za-z0-9]*)$ index.php?group=$1\&section=$2\&category=$3 [T=application/x-httpd-php,L]

3) Here is a sample of index.php
<html>
<body>
<?php
echo "$QUERY_STRING\n";
?>
</body>
</html>

As you can see, for /foo, the group would then be foo while section and category get an empty variable.

>> you could put them inside httpd.conf

That's almost a must for performance and reliability.

Reply With Quote
  #8  
Old July 22nd, 2001, 12:42 PM
jizzaz jizzaz is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jul 2001
Posts: 13 jizzaz User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 36 m 24 sec
Reputation Power: 0
Thumbs up

Halleluja!!
Finally I get to see the magic of mod_rewrite!

To freebsd, Thanks a millions your code worked great except for:

RewriteRule ^([A-Za-z0-9]+)/?([A-Za-z0-9]*)/?([A-Za-z0-9]*)$ index.php?group=$1\&section=$2\&category=$3 [T=application/x-httpd-php,L]
Was giving me extra slashes
Ex.
http://linuxbox.localhost/Produce/Fruits/Apples

(//filename:index.php
<?php
echo $group.$section.$category;
?>)
would result in:
Produce//Fruits//Apples

Remove the slashes from \& to & and you get:
ProduceFruitsApples

Perfect!

Quote:
you could put them inside httpd.conf.
If they works OK, then the problem could be that .htaccess is not recognized properly


Yeah, the code above did not work in .htaccess but did work in httpd.conf.

Why would .htaccess not be recognized properly? Do I need to edit something in httpd.conf?

Bottom Line it works! Thanks again freebsd and pippo

Reply With Quote
  #9  
Old July 22nd, 2001, 05:19 PM
freebsd freebsd is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jan 2001
Posts: 5 freebsd User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
>> Remove the slashes from \& to & and you get: ProduceFruitsApples

If you read the forefront thread again, you would see I didn't escape the & character with a slash for ($1\&section=$2\&category=$3). Forefront believed the additional slash was OS dependent which I haven't confirmed.

It worked on FreeBSD with and without the slash. Just a wild guess, it could be the reason that your mod_php doesn't have --with-system-regex enabled.

>> Why would .htaccess not be recognized properly?

Start here -> http://httpd.apache.org/docs/mod/mo...l#RewriteEngine

Syntax: RewriteEngine on|off
Default: RewriteEngine off
Context: server config, virtual host, directory, .htaccess
Override: FileInfo
Status: Extension
Module: mod_rewrite.c
Compatibility: Apache 1.2

In order for RewriteEngine in .htaccess being parsed by Apache, you need to have AllowOverride FileInfo.

Reply With Quote
Reply

Viewing: Dev Shed ForumsSystem AdministrationApache Development > mod_rewrite offline / on http://localhost?


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 6 hosted by Hostway