Forum Moderators: phranque
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
"GET /admin/editpage HTTP/1.1" 500 2056
as the last activity.
Don't know if that helps. Suppose it depends what 2056 implies.
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
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]
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
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
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]
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
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