0

This is what I have so far in my development environment:

php_value error_log log/php.log
php_value display_errors 1
php_value magic_quotes_gpc Off

RewriteEngine On

# remove slash
RewriteCond %{REQUEST_FILENAME} !-d

# file.php to /file
RewriteCond %{THE_REQUEST} ^(.+)\.php([#?][^\ ]*)?\ HTTP/
RewriteCond %{REQUEST_URI} !^/ajax.php
RewriteRule ^(.+)\.php$ http://localhost/$1 [R=301,L]

# /file to file.php
RewriteRule ^([^/.]+)$ $1.php [L]

I've tried a lot of variants of this rule but I always get a 500 error:

RewriteRule ^(.*)$ /book.php?url=$1 [L]

And this is in my Apache's error.log:

[Fri Jul 27 19:56:51 2012] [error] [client 127.0.0.1] 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.

What am I missing, why the redirect loop?

unor
  • 92,415
  • 26
  • 211
  • 360
whallz
  • 2,365
  • 2
  • 22
  • 24
  • also, is there a way to make rules completely independent from the domain? I'd like to avoid changing this file in local/qa/prod environments – whallz Jul 27 '12 at 23:09
  • 2
    Or simply `RewriteRule ^book/([^/]*)$ /book.php?id=$1 [L]`. And last but not least, try to add: `RewriteBase /` – Fabio Mora Jul 31 '12 at 22:30

2 Answers2

4

Your RewriteRule as written appears to be trying to do opposite of what your question headline is saying. You say that you want htaccess rewrite /book.php?id=1234 to /book/1234, but your RewriteRule:

RewriteRule ^(.*)$ /book.php?url=$1 [L]

Is adding a query string parameter.

The RewriteRule below will rewrite rewrite /book.php?id=1234 to /book/1234

RewriteCond %{QUERY_STRING} ^id=([0-9]*)$
RewriteRule ^book\.php$ /book/%1? [L]

Also, if you really wish to go the other way, i.e. rewrite /book/1234 to /book.php?id=1234 the following should do that:

RewriteRule ^book/(.*)$ /book.php?id=$1 [L]
HeatfanJohn
  • 7,143
  • 2
  • 35
  • 41
1

try this!

# in htaccess file write this
RewriteEngine on 

RewriteRule ^book/([0-9]+) book.php?id=$i

# and in you html or php file call

book.php?id=$i 

page by

book/$i 

you are done.

Suraj Rao
  • 29,388
  • 11
  • 94
  • 103
suraj
  • 326
  • 4
  • 6