Forum Moderators: phranque

Message Too Old, No Replies

Getting mod rewrite to run

Cannot figure out which setting I am missing..

         

leatherback

8:41 am on Aug 27, 2005 (gmt 0)

10+ Year Member



Dear All,

My first post here. After trying for 2 days, and failing in my normal forum to get the answer I am looking for, I have decided to turn nto you guys. hope you can help me get things running properly! Unfortunately the search functionality for the sitre appears to be down. So please bear with me..

I am running Apache/1.3.27 on windows 2000 pro.
This came in a pre-compiled package of apache / mysql / PhP. Although everything is getting a bit old, I have the same setup now as my ISP, whgich is kind of convenient.

I am trying to get Mod Rewrite to work. But somehow I cannot figure out what I have missed. My settings:

LoadModule rewrite_module modules/mod_rewrite.so

AddModule mod_rewrite.c

DocumentRoot "F:/webroot/"

<Directory "F:/webroot/">
Options Indexes FollowSymLinks MultiViews Includes ExecCGI
AllowOverride All
Order allow,deny
Allow from localhost 127.0.0.1
</Directory>

What is wrong? I read in one of the posts that Mod rewite needs to be compiled into the serversoftware. How do I check whether this has been done?

I hope you can help me, it got me bogged down at the moment.

Thanks!

Jelle.

ChadSEO

3:58 pm on Aug 29, 2005 (gmt 0)

10+ Year Member



leatherback,

Welcome to WebmasterWorld!

Some more information on exactly what is wrong would be helpful. Does Apache not start? Try testing the configuration and see what messages you get. Do you get an error code when trying to access pages? What error code, and what do the entries in the error_log say? Does the site work, but your mod_rewrite directives do not? What are the Rewrite Rules you are trying?

Chad

leatherback

4:10 pm on Aug 29, 2005 (gmt 0)

10+ Year Member



Hi Chad,

Thank you!

Apache runs perfectly. No problems with that in itself. Only the rewrite module doesn't work. I was trying a very simple directory path -> variable redirect for starters;
in my .htaccess file:

Options +FollowSymLinks
RewriteEngine on
RewriteRule ^pics/(.*)/(.*)/$ pics.php?$1=$2

this does what I expect on the live server at my ISP, and loads page pics.php?variablename=variablevalue, in the underlaying directory. At home it just gives me the pics.php page, and the uri gives me /pics/var/value

so this:
portfolio/pics/c/Australia/

give this in the php, REQUEST_URI: portfolio/pics/c/Australia/
and the querystring is empty.

Hope you know what I need to set / change!

Thanx a bunch!

Jelle.

ChadSEO

4:59 pm on Aug 29, 2005 (gmt 0)

10+ Year Member



The REQUEST_URI is correct, that is the url that was actually requested. I'm not sure why the query string would be blank though. I just ran a quick test, and I was able to access the query string/URL parameters 2 ways: 1) using the $_GET[] array, and 2) using the $_SERVER['QUERY_STRING'] variable.

The following code displays both items, to verify they are correct.

print_r($_GET);
echo "QUERY_STRING: " . $_SERVER['QUERY_STRING'] . "\n<br>\n

Chad

leatherback

7:05 pm on Aug 29, 2005 (gmt 0)

10+ Year Member



Hi Chad,

THanks for your reply again.

The problem is not in the mod rewrite code. The code works. I verified this on the life server. The problem is getting my local machine to perform the rewrite. I also tried a redirect, which didn't work either. Somehow, I cannot get the rewrite engine to run.

Any other ideas would be appreciated!

J.

ChadSEO

7:32 pm on Aug 29, 2005 (gmt 0)

10+ Year Member



I'm not sure what might be causing the problem then. Probably what I would try next is add the following 3 lines to your httpd.conf file:

RewriteEngine On
RewriteLog c:\temp\rewrite_log
RewriteLogLevel 2

Then test the configuration, and if it passes, restart Apache. This will 1) insure that mod_rewrite is loaded, and 2) create a log file to tell you if mod_rewrite is getting called at all.

Chad

leatherback

8:02 pm on Aug 29, 2005 (gmt 0)

10+ Year Member



Hi Chad,

Thanks, that is helping somewhat..

Calling the url:
[localhost...]

gives in the log (Besides some 20 more lines for the linked images / includes):
127.0.0.1 - - [29/Aug/2005:22:13:59 +0200] [localhost/sid#7958c8][rid#898ef8/initial] (2) init rewrite engine with requested uri /bio-vision/website/portfolio/pics/c/australia
127.0.0.1 - - [29/Aug/2005:22:13:59 +0200] [localhost/sid#7958c8][rid#898ef8/initial] (1) pass through /bio-vision/website/portfolio/pics/c/australia
127.0.0.1 - - [29/Aug/2005:22:13:59 +0200] [localhost/sid#7958c8][rid#898ef8/initial] (1) [per-dir f:/webroot/bio-vision/website/portfolio/] pass through f:/webroot/bio-vision/website/portfolio/pics.php
127.0.0.1 - - [29/Aug/2005:22:13:59 +0200] [localhost/sid#7958c8][rid#894e68/subreq] (2) init rewrite engine with requested uri /c/australia
127.0.0.1 - - [29/Aug/2005:22:13:59 +0200] [localhost/sid#7958c8][rid#894e68/subreq] (1) pass through /c/australia
127.0.0.1 - - [29/Aug/2005:22:14:00 +0200] [localhost/sid#7958c8][rid#894e68/initial] (2) init rewrite engine with requested uri /bio-vision/website/portfolio/pics/c/australia
127.0.0.1 - - [29/Aug/2005:22:14:00 +0200] [localhost/sid#7958c8][rid#894e68/initial] (1) pass through /bio-vision/website/portfolio/pics/c/australia
127.0.0.1 - - [29/Aug/2005:22:14:00 +0200] [localhost/sid#7958c8][rid#894e68/initial] (1) [per-dir f:/webroot/bio-vision/website/portfolio/] pass through f:/webroot/bio-vision/website/portfolio/pics.php
127.0.0.1 - - [29/Aug/2005:22:14:00 +0200] [localhost/sid#7958c8][rid#89e570/subreq] (2) init rewrite engine with requested uri /c/australia
127.0.0.1 - - [29/Aug/2005:22:14:00 +0200] [localhost/sid#7958c8][rid#89e570/subreq] (1) pass through /c/australia
127.0.0.1 - - [29/Aug/2005:22:14:00 +0200] [localhost/sid#7958c8][rid#894e68/initial] (2) init rewrite engine with requested uri /bio-vision/website/portfolio/pics/c/australia
127.0.0.1 - - [29/Aug/2005:22:14:00 +0200] [localhost/sid#7958c8][rid#894e68/initial] (1) pass through /bio-vision/website/portfolio/pics/c/australia
127.0.0.1 - - [29/Aug/2005:22:14:00 +0200] [localhost/sid#7958c8][rid#894e68/initial] (1) [per-dir f:/webroot/bio-vision/website/portfolio/] pass through f:/webroot/bio-vision/website/portfolio/pics.php
127.0.0.1 - - [29/Aug/2005:22:14:00 +0200] [localhost/sid#7958c8][rid#89e570/subreq] (2) init rewrite engine with requested uri /c/australia
127.0.0.1 - - [29/Aug/2005:22:14:00 +0200] [localhost/sid#7958c8][rid#89e570/subreq] (1) pass through /c/australia

What does this tell me!?

Thanks so much!

Jelle.

jdMorgan

9:04 pm on Aug 29, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



It looks like your document root is set incorrectly. Set DocumentRoot to the highest-level directory that you want to be accessible by Web users, probably f:/webroot/bio-vision/website/

Your .htaccess file residing in /website would then contain:


Options +FollowSymLinks
RewriteEngine on
RewriteRule ^[b]portfolio/[/b]pics/([^/]+)/([^/]+)/?$ pics.php?$1=$2 [L]

or if the .htaccess file is located in /portfolio, your original code would work:

Options +FollowSymLinks
RewriteEngine on
RewriteRule ^pics/([^/]+)/([^/]+)/?$ pics.php?$1=$2 [L]

Other changes to the rules above are for efficiency only.

Jim

leatherback

9:49 pm on Aug 29, 2005 (gmt 0)

10+ Year Member



Hi,

The .htaccss is in the portfolio folder. This my local machine, on which I work on the site, before putting it life. So I do not mind getting acces too directories. However, your optimized code doesn't work :-(

The .htaccess file:
Options +FollowSymLinks
RewriteEngine on
RewriteRule ^pics/([^/]+)/([^/]+)/?$ pics.php?$1=$2 [L]

the rewritelog (For the main section, not included files):
127.0.0.1 - - [29/Aug/2005:23:40:54 +0200] [localhost/sid#7958c8][rid#422f0c0/initial] (2) init rewrite engine with requested uri /bio-vision/website/portfolio/pics/c/australia/
127.0.0.1 - - [29/Aug/2005:23:40:54 +0200] [localhost/sid#7958c8][rid#422f0c0/initial] (1) pass through /bio-vision/website/portfolio/pics/c/australia/
127.0.0.1 - - [29/Aug/2005:23:40:54 +0200] [localhost/sid#7958c8][rid#422f0c0/initial] (1) [per-dir f:/webroot/bio-vision/website/portfolio/] pass through f:/webroot/bio-vision/website/portfolio/pics.php
127.0.0.1 - - [29/Aug/2005:23:40:54 +0200] [localhost/sid#7958c8][rid#42310e8/subreq] (2) init rewrite engine with requested uri /c/australia/
127.0.0.1 - - [29/Aug/2005:23:40:54 +0200] [localhost/sid#7958c8][rid#42310e8/subreq] (1) pass through /c/australia/
127.0.0.1 - - [29/Aug/2005:23:40:54 +0200] [localhost/sid#7958c8][rid#898ef8/initial] (2) init rewrite engine with requested uri /bio-vision/website/portfolio/pics/c/australia/
127.0.0.1 - - [29/Aug/2005:23:40:54 +0200] [localhost/sid#7958c8][rid#898ef8/initial] (1) pass through /bio-vision/website/portfolio/pics/c/australia/
127.0.0.1 - - [29/Aug/2005:23:40:54 +0200] [localhost/sid#7958c8][rid#898ef8/initial] (1) [per-dir f:/webroot/bio-vision/website/portfolio/] pass through f:/webroot/bio-vision/website/portfolio/pics.php
127.0.0.1 - - [29/Aug/2005:23:40:54 +0200] [localhost/sid#7958c8][rid#419f5d0/subreq] (2) init rewrite engine with requested uri /c/australia/
127.0.0.1 - - [29/Aug/2005:23:40:54 +0200] [localhost/sid#7958c8][rid#419f5d0/subreq] (1) pass through /c/australia/
127.0.0.1 - - [29/Aug/2005:23:40:54 +0200] [localhost/sid#7958c8][rid#898ef8/initial] (2) init rewrite engine with requested uri /bio-vision/website/portfolio/pics/c/australia/
127.0.0.1 - - [29/Aug/2005:23:40:54 +0200] [localhost/sid#7958c8][rid#898ef8/initial] (1) pass through /bio-vision/website/portfolio/pics/c/australia/
127.0.0.1 - - [29/Aug/2005:23:40:54 +0200] [localhost/sid#7958c8][rid#898ef8/initial] (1) [per-dir f:/webroot/bio-vision/website/portfolio/] pass through f:/webroot/bio-vision/website/portfolio/pics.php
127.0.0.1 - - [29/Aug/2005:23:40:54 +0200] [localhost/sid#7958c8][rid#419f5d0/subreq] (2) init rewrite engine with requested uri /c/australia/
127.0.0.1 - - [29/Aug/2005:23:40:54 +0200] [localhost/sid#7958c8][rid#419f5d0/subreq] (1) pass through /c/australia/

I am not sure how to read this, or what it states. So it is bit hard for me to tell what does or doesn't work.. But this means that the rewrite engine works?

The $_GET array / querystring are still empty.

Now I created a folder modwritetest with a .htaccess file:
tions +FollowSymLinks
RewriteEngine on

RewriteRule index.html index.php?task=1

and when I call index.html it opens index.php and echoes out $task, which is 1. SO the rewrite engine works, but the rule is misunderstood?

Thanks,

jelle.

ChadSEO

10:05 pm on Aug 29, 2005 (gmt 0)

10+ Year Member



Jelle,

print_r($_SERVER);

If you put that at the top of your pics.php file, it should print out all the variables in $_SERVER, although you may need to do a view-source for it to be legible. When I tested this, both REDIRECT_QUERY_STRING and QUERY_STRING had the correct values (1=2 for /pics/1/2/). If you do test this, are they just empty?

Chad

leatherback

10:14 pm on Aug 29, 2005 (gmt 0)

10+ Year Member



Progress.

Now, I created this rule:
RewriteRule pics(.*) pics.php\?$1 [L]

calling it at [localhost...]
which will give me page pics.php, with one entry in the get array, where the key is/c/australia/, no value.

Now, I modified the rule to
RewriteRule pics/(.*) pics.php\?$1 [L]
and / or
RewriteRule pics\/(.*) pics.php\?$1 [L]

which do not work. So appearently it is not matching the slashes. Am I missing something completely obvious!?

J.

leatherback

10:20 pm on Aug 29, 2005 (gmt 0)

10+ Year Member



Oh, chad:
I checked. There is no redirect_query_string, and the QUERY_STRING is empty.

:-(

ChadSEO

10:37 pm on Aug 29, 2005 (gmt 0)

10+ Year Member



Jelle,

I'm not sure why that's not working for you, it's working fine on my test rig. The only difference I can think of is I'm on Linux, instead of Windoze. Hopefully Jim has some more suggestions for you, I'm fresh out of ideas.

Good luck!
Chad

leatherback

10:43 pm on Aug 29, 2005 (gmt 0)

10+ Year Member



Hi Chad,

THanks for your help.

It really feels like good ol'MSh*t indeed. I wish I never started working on these windows machines. Unfortuantely.. I have all my software in MS format. Kinda expensive thing to swap now. Who knows.. Next year.

This rule:
RewriteRule ([a-z])/([^/]+)/([^/]+)/$ pics.php\?$2=$3 [L]

left to work on:
[localhost...]

gives me pics.php, with $_GET['c'] = australie,

so I suppose I could use that. I am completely amazed why it will not accept a slash in the first string-set, but it is ok in the rest of the pattern. Anyway. Your log-swicching helped a lot. DIdn;t know that option. Now I can at least see when the rewrite kicks in, and what it tries. I am 99% there. Just need to check wether this works 'live' as well, and whether there is funny side-effects..

Still.. any other solutions are welcome too (THis is not the sweetest rewrite I can think of)

J.