views:

21

answers:

1

i have this url that i wanted to make friendly, using rewrite on .htacess but it gives me an error(500 internal server error), this is my orginal php url

http://www.example.com/viewtopic.php?topic=lovetopic

i want to change it to this:

http://www.example.com/lovetopic

this is my whole htaccess code is this:

RewriteEngine On
RewriteRule ^user/([^/]*)$ /viewprofile.php?user=$1 [L]
RewriteRule ^([^/]*)$ /viewtopic.php?topic=$1 [L]

i dont know what the problem is

EDIT the server error log is giving me this error

[Thu Oct 14 20:34:36 2010] [error] Request exceeded the limit of 10 internal redirects due to probable configuration error. Use 'LimitInternalRecursion' to increase the limit if necessary. Use 'LogLevel debug' to get a backtrace., 
+3  A: 

The pattern of your second rule ^([^/]*)$ does also match /viewtopic.php without the path prefix /, i.e. viewtopic.php. That’s why you’re having an infinite recursion.

You can use the following condition to exclude that:

RewriteCond $1 !=viewtopic.php
RewriteRule ^([^/]*)$ /viewtopic.php?topic=$1 [L]

Or use this condition to exclude all existing files:

RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^([^/]*)$ /viewtopic.php?topic=$1 [L]

Or use this rule in front of you other rules to stop every request that can be mapped to an existing file being rewritten by any following rules:

RewriteCond %{REQUEST_FILENAME} -f
RewriteRule ^ - [L]
Gumbo
Shouldn't The `[L]` tag already be preventing recursion?
R. Bemrose
D'oh, I just checked... no, `[L]` doesn't prevent internal redirects from causing all rules to be reprocessed on the new url.
R. Bemrose
@R. Bemrose: No, the [ *L* flag](http://httpd.apache.org/docs/2.2/mod/mod_rewrite.html#rewriteflags) is a little bit different: “Remember, however, that if the RewriteRule generates an internal redirect (which frequently occurs when rewriting in a per-directory context), this will reinject the request and will cause processing to be repeated starting from the first RewriteRule.”
Gumbo
thank you this works, :)), the problem is i have a file called home.php which is the homepage, and the system thinks its a topic rather than the homepage? :)) if you know what i mean, so what rule should i use lol :))
getaway
@getaway: You may want to use the third example he posted before your existing rules. This will prevent what you see now (P.S. Deleted my answer, 'cause it was wrong)
R. Bemrose
@r.bremose thank you very much :)) you guys are geniuses god
getaway