Forum Moderators: coopster & phranque

Message Too Old, No Replies

mod_rewrite

use mod_rewrite to migrate from ?... to /

         

risky

11:16 am on Jul 24, 2002 (gmt 0)

10+ Year Member



Yet another question on mod_rewrite. I have looked at other messages on these boards and found similar posts but I am unable to get this working. I want all pages under /root/dir1/dir2/ to call a specific php page - file.php. So a request for .../root/dir1/dir2/var1/var2 will call file.php which will use var1 and var2.

I have:

RewriteEngine on
RewriteBase /root/dir1/dir2/
RewriteRule ^file.php test.html [T=application/x-httpd-cgi,L]

which I have basically put together according to other posts and I don't claim to fully understand it.

.htaccess resides in directory dir2

Currently the page returned is a 500 internal server error. I have tried writing different bits for rewriteBase (should this be relative to the position of .htaccess or from the root?) and rewriteRule.

Help would be greatly appreciated :)
Risky

Brett_Tabke

11:30 am on Jul 24, 2002 (gmt 0)

WebmasterWorld Administrator 10+ Year Member Top Contributors Of The Month



Welcome to the forums risky.

First, get mod_rewrite working without php. Just go to a new html file to make sure it is working and call files on the right path.

Brett_Tabke

11:36 am on Jul 24, 2002 (gmt 0)

WebmasterWorld Administrator 10+ Year Member Top Contributors Of The Month



Try something like

RewriteEngine on
RewriteBase /
RewriteRule ^fred.html nohead.html

That should substitute a call to "nohead.html" from a call to fred.html.

make sure both files exist and have unique content (so you can tell which is really being served). Then try to call fred.html in the browser and see what happens. From there, it is just a matter of tweak the paths and files, but you need to make sure mod_rewrite is up and running first.

risky

1:20 pm on Jul 24, 2002 (gmt 0)

10+ Year Member



Thanks Brett, exactly the sort of thing I was looking for.

I set up the files exactly as you suggested - called fred just to make sure and then saved the .htaccess to that directory. This resulted in an internal server error again.

I guess that I am unable to use mod_rewrite. I am going to have a word with the administrator to see if he understands what I am trying to do. Is it possible for me to check whether I have rights to use this command?

Brett_Tabke

3:14 pm on Jul 25, 2002 (gmt 0)

WebmasterWorld Administrator 10+ Year Member Top Contributors Of The Month



Ya, if the two files are in your root space, that should have worked (the rewrite base specifies the offset path).

Do you have access to the error logs? Did anything popup when you tried the above? If you do have error log access, it will flag an error when you try to turn on the rewrite engine.

Knowles

4:57 pm on Jul 25, 2002 (gmt 0)

10+ Year Member



You mentioned PHP earlier you can also check by making a PHP page with phpinfo(); this will list all your options it will tell you if mod_rewrite is on. Itll be in LoadedModuals under Apache. There will be all kinds of other interesting info on there as well.

risky

9:14 am on Jul 26, 2002 (gmt 0)

10+ Year Member



Ah, thanks Knowles. I am fairly new to php and didn't think to look under phpinfo(). Looks like it isn't currently available, I will annoy some people until they get it sorted. Thanks to both of you for your help.

misosoph

9:47 am on Jul 26, 2002 (gmt 0)

10+ Year Member



May I ask for clarification?

First, I set up and ran a "^fred.html nohead.html" test and the redirect worked -- that is, I asked for fred.html and got the content of nohead.html instead. I did this with two servers, one using Apache with Solaris, and the other using Apache with Linux.

Second, I created a plain-text file containing only the line:

<?php phpinfo(); ?>

and I named it "phpinfo.php"

Then on both servers, when I requested phpinfo.php, I got long pages with the on-page titles of "PHP Version 4.2.1" and "PHP Version 4.1.2"

However on neither of these pages can I find any mention of "mod_rewite" or "LoadedModuals". So, please tell me the exact phrase I should be looking for. Thank you.

risky

1:12 pm on Jul 26, 2002 (gmt 0)

10+ Year Member



On that page there should be a section titled apache, within that table there is a row 'Loaded Modules' which will contain 'mod_rewrite' if it exists.

misosoph

1:58 pm on Jul 26, 2002 (gmt 0)

10+ Year Member



Thank you. I am not finding a section named "apache". This is what I have on the page I see:

PHP Version 4.1.2

PHP 4.0 Credits

Configuration

PHP Core
xml
standard
session
posix
pcre
mysql
gd
ftp
dba
bcmath
zlive

Additional Modules
environment
php variables

php license

The word "apache" only appears 3 times on this page in
environment:
SERVER_SOFTWARE Apache/1.3.26 (Unix)
php variables:
_SERVER["SERVER_SOFTWARE"] Apache/1.3.26 (Unix)
_ENV["SERVER_SOFTWARE"] Apache/1.3.26 (Unix)

Am I looking at the wrong page? Did I put the file I created in the wrong directory? Here is where I put it:

http*//my-domain/phpinfo.php

As to mod_rewrite, that was the point of the "^fred.html nohead.html" test, wasn't it? And since that test is positive on this server, mustn't mod_rewrite be available on this server?

Knowles

2:04 pm on Jul 26, 2002 (gmt 0)

10+ Year Member



Yes it seems to be on for you since it did that, I am not sure why its not showing all the sections for you when you do the phpinfo(). It looks like it is loading bits and peices of the page. It could possibly b a version difference. I am on 4.0.6.

misosoph

2:22 pm on Jul 26, 2002 (gmt 0)

10+ Year Member



It's just curiousity, really. Knowing that mod_rewrite is available to me is what matters. And you've told me that. So that's all. Thank you.