Forum Moderators: phranque
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.
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
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.
The following code displays both items, to verify they are correct.
print_r($_GET);
echo "QUERY_STRING: " . $_SERVER['QUERY_STRING'] . "\n<br>\n
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.
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
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.
Your .htaccess file residing in /website would then contain:
Options +FollowSymLinks
RewriteEngine on
RewriteRule ^[b]portfolio/[/b]pics/([^/]+)/([^/]+)/?$ pics.php?$1=$2 [L]
Options +FollowSymLinks
RewriteEngine on
RewriteRule ^pics/([^/]+)/([^/]+)/?$ pics.php?$1=$2 [L]
Jim
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.
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
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.
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.