RewriteRule .htaccess多个参数

时间:2014-04-10 02:05:55

标签: php apache .htaccess mod-rewrite

我正在尝试重写我的网址,但是我收到错误“500内部服务器错误”

我之前从未这样做过,而且我已经阅读了一些教程,但我不能说我从中得到了更多更聪明。

.htaccess文件位于根目录(/ var / www)

Options +FollowSymLinks
RewriteEngine On

RewriteBase /sub_domain/directory_to_my_files/
RewriteRule ^([0-9.]+)-([0-9.]+)/(.*)/$ /index.php?pos=$1:$2&text=$3

目前的链接如下: http://sub_domain.my_domain.com/directory_to_my_files/index.php?pos=(float|integer-only):(float|integer-only)&text=(any-text)

但我正在尝试这样做: http://sub_domain.my_domain.com/directory_to_my_files/(float|integer-only):(float|integer-only)/(any-text)/

很抱歉,如果链接有点难以阅读。

2 个答案:

答案 0 :(得分:0)

我在本地进行了测试: (我不需要重写基础)

RewriteEngine on
RewriteRule ^([0-9.]+)-([0-9.]+)/(.*) /index.php?pos=$1:$2&text=$3 [R,L]

它重定向了我 来自

http://loc.domain/555-666/misc-text

http://loc.domain/index.php?pos=555:666&text=misc-text

我认为这是你想要的?

关于[R,L]结尾: R告诉apache实际重定向,而不仅仅是重写url - 这有助于测试。 L说这是最后一条规则

编辑:可能是rewriteBase导致你出现问题吗?尝试没有,看它是否有效 - 至少你可以指出问题出在哪里,然后。

答案 1 :(得分:0)

这应该放在 /directory_to_my_files/.htaccess

RewriteEngine On
RewriteBase /directory_to_my_files/

RewriteRule ^(-?[0-9.]+)[:-]([0-9.]+)/([^/]+)/?$ index.php?pos=$1:$2&text=$3 [L,QSA,NE]