.htaccess rewrite “/book.php?id=1234” to “/book/1234”

前端 未结 2 1989
天命终不由人
天命终不由人 2020-11-30 14:58

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

RewriteE         


        
相关标签:
2条回答
  • 2020-11-30 15:18

    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]
    
    0 讨论(0)
  • 2020-11-30 15:32

    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.

    0 讨论(0)
提交回复
热议问题