Forum Moderators: phranque
I'm in a directory mysite.com/ and I want to rewrite all requests for a sub-directory to a php script. So mysite.com/subdir gets rewritten to mysite.com/script.php?var=subdir
What I came up with is this (assume RewriteEngine on):
rewriteRule ^(.*) /script.php?var=$1 [L]
But that returns a 500 internal error. What's weird is if I try
rewriteRule ^test/(.*) /script.php?var=$1 [L]
and give the server a request for mysite.com/test/subdir it works. Why does it work for one and not the other? Thanks.
RewritCond $1 !^script\.php$
RewriteRule (.*) /script.php?var=$1 [L]
Jim
When the regular expression matches my string in (.*) it gets rewriten to script.php with the query string attached. So my question: by rewriting to script.php there's a whole new http request that goes through a whole new iteration through the .htaccess file? That would make a lot of sense. For some reason I didn't think the .htaccess file would be iterated through more than once.
mod_rewrite rules are iterated in .htaccess so that further rewrites can be applied -- particularly those having to do with access control. Note that the [L] flag stops processing only within one such iteration.
Jim
RewriteRule ^people$ people/ [R]
RewriteRule ^people/$ peeps.php [L]
This returns a 404 error when requesting http://example.com/dir/people, but rewriting the first line as
RewriteRule ^people$ /dir/people/ [R]
does the trick (peeps.php is displayed). Also removing the R flag correctly displays peeps.php, but without the added forward slash that I want. I would like to not have to specify the /dir/ directory for the first line, in case I move the contents to a different place on the server. Do I always have to specify the full path from the web root when using the R flag?
[edited by: jdMorgan at 10:20 pm (utc) on Jan. 15, 2008]
[edit reason] example.com [/edit]
It seems there's some apache directive in the httpd.conf file (which I don't have access to) that is making apache automatically handle php files without their extension. For example, requesting http://example.com/people refers to http://example.com/people.php (even if I have a rewrite rule that matches ^people$)
This is a bit troublesome, because then I have to make sure all the request URIs that I'm trying to match in my rewrite rules don't have a directory that shares it's name with a php file (minus the extension) in that directory.
What directive could be causing this, and is there any way to override it with directives in my .htaccess file? If not I'll have deal with the inconvenience of naming my php files with less intuitive names (not a big deal but I'm pretty curious as well).
Jim
[httpd.apache.org...]
The problem is in turning it off. MultiViewsMatch in mod_mime doesn't have an option for not matching anything, and specifying -MultiViews in Options just serves up a 500 error (and oddly also if i specify +MultiViews).
The only thing I can think to do now is getting rid of all the mime types that are specified with mod_mime's directives for .php files, but I'm not even sure this would work (or even if it's a good idea), plus I have no access to httpd.conf. How do I find out where my error logs are for apache? I probably need to take a look at those, as well as the actual httpd.conf file. Any ideas?
500-Server Error
Jim
[edited by: jdMorgan at 3:10 pm (utc) on Jan. 16, 2008]