Forum Moderators: phranque

Message Too Old, No Replies

RewriteBase problem?

RewriteBase problem

         

richiebman

11:04 am on Aug 21, 2004 (gmt 0)

10+ Year Member



Hello all,

I am very new to this mod_rewrite .htaccess stuff (ie:last night) and so I have a problem that is most likely super simple to solve.

I wanted clean urls and found this script which works great:

AddHandler cgi-script .wow
RewriteEngine on
RewriteBase /
RewriteCond %{REQUEST_FILENAME}.wow -f
RewriteCond %{REQUEST_URI}!/$
RewriteRule (.*) $1\.wow [L]

I converted my file extensions to .wow (this is more of an experiment) and the code in my files is php (I also put #!/usr/local/bin/php at the top of my .wow files). So on my site I can call a file without an extension (eg: <a href="./home">Home</a> and it displays /home in the url bar. The above code also parses the files as php.

This all works great. But now I am linking to another .wow file in a folder called admin on the root directory. This doesn't work.

Firstly I was getting a 404 error so I put a .htaccess file (with the same above code) in the admin folder to solve this. This didn't work so I started playing around with the RewriteBase line. I tried:

RewriteBase /admin/

and now I get a 500 error.

Anyone know where I'm going wrong?
Cheers,
R

moltar

2:43 pm on Aug 21, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



What does the log file state for 500 error?

richiebman

3:00 pm on Aug 21, 2004 (gmt 0)

10+ Year Member



Excuse my ignorance.....where would I find the log file?

moltar

5:57 pm on Aug 21, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



It varies from hosting to hosting. Ask your hosting provider for the path to the error log file.

richiebman

6:34 pm on Aug 21, 2004 (gmt 0)

10+ Year Member



I've actually just been looking in my logs folder, which I completely forgot about, but there is no error log file. There are several files that when viewed are complete gibberish. The only one that contained readable information was an access.log file. I clicked on the link to take me into the admin folder which gave me an internal server error. Then I viewed access.log and found

"GET /admin/editpage HTTP/1.1" 500 2056

as the last activity.

Don't know if that helps. Suppose it depends what 2056 implies.

jdMorgan

6:53 pm on Aug 21, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Rather than type all this in, I think it's wise to just refer you to [httpd.apache.org...]

Jim

richiebman

1:08 am on Aug 22, 2004 (gmt 0)

10+ Year Member



Yeah I read all that JDMorgan, but it doesn't help my original problem. I know my root .htaccess file is correct.....because it works no problem. But because my knowledge of mod_rewrite is new and basic, I can't begin to understand where I might be going wrong.

The way I'm thinking is that

RewriteRule /admin/

is correct, otherwise you would have told me so, but that maybe the other conditions have to be manipulated to accomodate a new directory position.?

I really don't know, so you'll have to excuse me...this is a new way of altering file access for me. Plus I'm absolutly wasted and I'm atually pretty pleased that I've been able to type this far without passing out.

I will now pass out..........:{@@:@:K*&%$&$

Ta
R

richiebman

10:41 am on Aug 22, 2004 (gmt 0)

10+ Year Member



I asked my server people and they said I don't have access to my error log, which is a bit poor.

Apologies for my last drunken reply. Really would appreciate you guys still helping me out.

Cheers,
R

gergoe

11:27 am on Aug 22, 2004 (gmt 0)

10+ Year Member



Try this one in your root .htaccess (and take away the rest of the htaccess files):

AddHandler cgi-script .wow
Options +FollowSymLinks
RewriteEngine on
RewriteBase /
RewriteCond %{DOCUMENT_ROOT}/%{SCRIPT_FILENAME}.wow -f
RewriteCond %{REQUEST_URI} !/$
RewriteCond %{REQUEST_URI} !\.((gif)¦(jpe?g)¦(css))$
RewriteRule ^(.+)(\.((wow)¦(html?)))?$ $1.wow [L]

richiebman

1:12 pm on Aug 22, 2004 (gmt 0)

10+ Year Member



Cheers Gergoe, but it didn't work. It seemed to have a problem with

RewriteCond %{DOCUMENT_ROOT}/%{SCRIPT_FILENAME}.wow -f

I kept getting a 300 multiple choices error on my main pages (and when I linked to a file in my admin folder) until I substitued the above line for my original line

RewriteCond %{REQUEST_FILENAME}.wow -f

Then it worked but I still got an internal server error when I linked to files in my admin folder. And I had taken the admin .htaccess file out.

I did some more tests with the below .htaccess file in my admin folder. I simplyfied it incase any of the RewriteConds were the problem:

AddHandler cgi-script .wow
Options +FollowSymLinks
RewriteEngine on
RewriteBase /admin/
RewriteRule ^editpage$ editpage.wow

(editpage.wow is a file in the admin folder)
Now surely that should work!? But it doesn't - 500 error. But when I change 'admin' to 'admins', I get a 404 error. When I remove RewriteBase, I get a 404 error. Which has my thinking that the RewriteBase line is correct, I'm just missing something else somewhere.

The only other thing that I can think of is that you can't use mod_rewrite in a folder unless it's the root. But that would be pretty pants if that was true.

R

richiebman

1:43 pm on Aug 22, 2004 (gmt 0)

10+ Year Member



OK. I really simplyfied things now. I cut the .htaccess file in my admin folder down to

AddHandler cgi-script .wow

merely to parse the files with a .wow extension as php. Just like I'm doing it in my root folder. At the top of all the files I want to behave like this, I put

#!/usr/local/bin/php

and chmod them to 755. Then I simply called www.mydomain.com/admin/editpage.wow and it threw up a 500 error! Why the *&^% should that happen?

Cheers for helping my on the mod_rewrite thing. My original Rewrite code is probably correct, but of course wouldn't work if I can't get the .wow files to parse as php. I hate computers!

Should I strat this new problem as a new post?

Cheers,
R

jdMorgan

2:21 pm on Aug 22, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



If you're getting a 300-Multiple Choices response, then you've got MultiViews (content negotiation) enabled, and that is going to interfere with what you are trying to do. Multiviews essentially does the same thing as your code, but it tries to find files with *any* file extension that match the requested partial filename. You code and MultiViews are therefore incompatible.

Again, without seeing your error log, this problem is difficult to diagnose, but I'd suggest changing your code to something more like this:


# Add handler
AddHandler cgi-script .wow
# Enable FollwSymLinks (required by mod_rewrite, disable MultiViews to prevent 300 error)
Options +FollowSymLinks -MultiViews
RewriteEngine on
RewriteBase /
# Don't rewrite directory requests
RewriteCond %{REQUEST_URI} !/$
# Don't rewrite if filetype specified in request
RewriteCond %{REQUEST_URI} !\.[a-z0-9]+$
# Check for file exists with .wow extension
RewriteCond %{DOCUMENT_ROOT}/%{SCRIPT_FILENAME}.wow -f
# Rewrite if .wow exists
RewriteRule ^(.+)$ $1.wow [L]

I moved the 'file exists' check so that it is the last RewriteCond. This will prevent your server from having to do this check for every request, and so improve performance slightly.

This still leaves open the question about your admin folder. It should not be necessary to use RewriteBase unless the admin folder is not in the directly-accessible URL-space of your site. In that case, if you've used an Alias directive to make it appear that the admin folder is URL-accessible, then you'll have to use RewriteBase to give mod_rewrite the 'true' path to the admin folder. Frankly, I would comment out your RewriteBase directive, work on finding out why you don't get an error log file and fixing that, and then use the error log on the 404 error to figure out what needs to be done next.

Jim

richiebman

10:35 am on Aug 23, 2004 (gmt 0)

10+ Year Member



Cheers for the help guys and sorry if I wasted your time, but it does seem that the reason why I was getting 500 errors was because - for some reason? - in the admin folder, the files weren't being parsed as php. I changed the file extensions to .php in the admin folder and the mod_rewrite code I originally put in my first post, worked fine. So I'm not sure why

AddHandler cgi-script .wow

wasn't working in the admin folder. For now I can leave the files as .php, but will want to change it in the future. Would be interested to hear from anyone who knows why this happened.

Thanks again,
R