Forum Moderators: phranque

Message Too Old, No Replies

why doesn't this rewrite.conf work?

mod_rewrite configuration for apache2

         

gnomes

4:58 am on Oct 18, 2005 (gmt 0)

10+ Year Member



for apache 2, this is my rewrite.conf

RewriteRule ^([A-Za-z0-9-]+).([A-Za-z0-9-]+)/?$ index.php?action=view&filename=$1.$2

It should make it so
mysite.com/file.ext
turns into
mysite.com/index.php?action=view&filename=file.ext

but it does nothing? Yes, the module is loaded, I can confirm this.

jd01

7:32 pm on Oct 18, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Hi gnomes,

Welcome to WebmasterWorld.

I am not sure what you mean by turns into? I recommend visiting the Apache Library [webmasterworld.com] and Forum Charter [webmasterworld.com] to get a better understanding of what mod_rewrite does.

There are a couple of corrections for your rule:

RewriteRule ^/([^.]+)\.(html?)$ /index.php?action=view&filename=$1.$2 [L]

The above will work for anything .htm or .html, but not .php to avoid looping.

The preceding / on the right side is required in the httpd.conf file.

If you are looking to show the rewrite to the users (redirect) you will need to add R=301, or R=30NUMBER to the L (last) flag at the end of the rule.

The L (last) flag will save you some processing -- generally should always be used unless you do not need it.

If you would like to define the regular expression, it is better to use [a-z0-9-] with the NC (No Case) flag added to the L flag on the rule than to add the A-Z set to the expression.

Hope this helps.

Justin

gnomes

12:07 am on Oct 19, 2005 (gmt 0)

10+ Year Member



i will be sure to try these and hopefully get it working, however it's important to note that it is not specifically other webpages that are being linked to but rather files.

by "turns into" i mean that is what it redirected to. thanks for your help.