0

I'm attempting to use htaccess to write my urls as localhost/username instead of localhost/profile.php?id=username

I looked it up and this is what I found to be the solution

DirectoryIndex index.php
RewriteEngine On
RewriteRule ^(.*)$ /profile.php?id=$1 [L]

That's an exact copy from this stackoverflow question htaccess rewrite for query string however, for some reason it always returns a 500 error. I'm not sure why it's giving me this since I'm no expert with htaccess. I pretty much just find code modify it to fit my use.

Mod_rewrite is definitely turned on. So I know that can't be the issue. Any idea what is wrong with the code I have?

Edit:

This is what the apache error log returned.

[Sat Apr 27 14:20:10.558122 2013] [core:error] [pid 3244:tid 1688] [client 127.0.0.1:58653] AH00124: 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.

Community
  • 1
  • 1

2 Answers2

1

If it's really a redirect loop per your comment, try adding this line immediately before your rule:

RewriteCond %{REQUEST_URI} !-f
Denis de Bernardy
  • 75,850
  • 13
  • 131
  • 154
  • Thanks, I think we're close. Unfortunately it still threw an error. But I changed the rule to `RewriteRule ^(.*)$ profile.php?user=$1 [L]` taking away the front slash before profile.php and now if I type in localhost/username it shows the profile.php template but doesn't query the database. Do I have to use $_SERVER["REQUEST_URI"] in my php code? –  Apr 27 '13 at 18:51
  • Add a `var_dump($_GET)` in your code somewhere to see what's wrong, and double check your php and mysql details. (Methinks this ought to be a new SO question, too) – Denis de Bernardy Apr 27 '13 at 18:56
  • If I can't get it to work after some of my own work I'll make a new question. Thanks again. –  Apr 27 '13 at 19:05
0

The part where it says /profile.php?id=$1 is where it will rewrite you to. If that;s not a file then it would show up with an error so change that to whatever file you want it to rewrite you to.

Hope this helped

  • Kevin
AKS
  • 4,618
  • 2
  • 29
  • 48
Kevin Harrison
  • 335
  • 1
  • 10