本文介绍了的.htaccess重写" /book.php ID = 1234"到" /电子书/ 1234 QUOT;的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是我至今在我的开发环境:

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]

我已经尝试了很多这个规则的变种,但我总是得到一个500错误:

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

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

这是在我的Apache的error.log中:

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?

推荐答案

重写规则书面似乎试图做你的问题标题是说的相反。你说你想要 htaccess的重写/book.php?id=1234到/电子书/ 1234 ,但你的重写规则

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.

在下面的重写规则将改写重写/book.php?id=1234到/电子书/ 1234

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]

此外,如果你真的想要走另一条路,即重写 /电子书/ 1234 /book.php?id=1234 下面应该这样做:

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

这篇关于的.htaccess重写" /book.php ID = 1234"到" /电子书/ 1234 QUOT;的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-16 01:13