Forum Moderators: phranque

Message Too Old, No Replies

htaccess rules are ignored, questions about rewrite syntax

         

besson3c

8:10 pm on Feb 23, 2006 (gmt 0)

10+ Year Member



Hi, a couple of questions...

For some reason, my rewrite rules only work when placed in my httpd.conf, they seem to be ignored in my .htaccess file in my Apache Documentroot. I have AllowOverride set to all in my httpd.conf file, all other htaccess commands are picked up, including commands in that very file.

Here is the .htaccess file in question (located in my DocumentRoot):


Redirect /courses http://journalism.indiana.edu/academics/courses

There are several more of these.. these redirects work just fine. Later in the same file, the following is listed:


<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{REQUEST_METHOD} ^TRACE
RewriteRule .* - [F]
RewriteRule ^/(admissionsnew¦admissionsnew/)$ /tech/wordpress/index.php?page_id=3
</IfModule>

The following:


RewriteCond %{REQUEST_METHOD} ^TRACE
RewriteRule .* - [F]

Are lines created by OS X Server I have copied here. What do they do? Are they needed?

The key rewrite rule that is ignored is this:


RewriteRule ^/(admissionsnew¦admissionsnew/)$ /tech/wordpress/index.php?page_id=3

This same rule works in my httpd.conf file. I'd rather use htaccess files, as I plan to create more rules and don't want to have to restart the server after making these changes.

Thanks in advance for your help!

jdMorgan

8:29 pm on Feb 23, 2006 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



besson3c,

Welcome to WebmasterWorld!

Note that in a per-directory (.htaccess) context, the path to that directory location is stripped for security (and server-admin convenience) reasons. This is mentioned in the mod_rewrite documentation.

For example, a rule in httpd.conf might be written:


RewriteRule ^/fruit/apples/big_red.html http://www.example.com/fruit/apples/big-red [R=301,L]

If this code were to be moved into the .htaccess file in the /fruit directory, it would need to change thus:

RewriteRule ^apples/big_red.html http://www.example.com/fruit/apples/big-red [R=301,L]

and then for use in the /apples/.htaccess file, thus:

RewriteRule ^big_red.html http://www.example.com/fruit/apples/big-red [R=301,L]

So the simple answer is that you need to remove at least the leading slash from the patterns used in .htaccess RewriteRules.

The rule pertaining to TRACE simply returns a 403-Forbidden response to any HTTP TRACE request.

Jim