-2

我相信这已被多次回答,但我无法找到答案。

我正在尝试让友好的 url 起作用,但无法编写重写规则。

我需要将www.mysite.com/123重写为www.mysite.com/index.php?page=123

还有一个页面,例如:www.mysite.com/123/abcwww.mysite.com/index.php?page=123&secondParam=abc

我也希望能够通过 www.mysite.com/something 链接到如下页面:www.mysite.com/something/index.php 并且不要将其重写为 www.mysite.com/index.php?page=something如果服务器上存在文件夹。

谢谢。

4

1 回答 1

2

试试这个。以“#”开头的行是注释,仅用于记录命令。

<IfModule mod_rewrite.c>
# calls to initiate our requests Apache's Rewrite Module (you need this only once)
RewriteEngine on

# "If the requests does not point to an existing file"
RewriteCond %{REQUEST_FILENAME} !-f
# "If the requests does not point to an existing folder"
RewriteCond %{REQUEST_FILENAME} !-d
# "If the request contains a "2 subfolders" structure, redirects it silently to ..."
RewriteRule ^([^/]+)/([^/]+)/?$ index.php?page=$1&secondParam=$2 [NC,QSA,L]
RewriteRule ^([^/]+)/?$ index.php?page=$1 [NC,QSA,L]
</IfModule>

试试这个版本的最后一行:

RewriteRule ^(.*)/(.*)/?$ index.php?page=$1&secondParam=$2 [NC,QSA,L]

或者

RewriteRule ^([A-Za-z0-9-]+)/([A-Za-z0-9-]+)/?$ index.php?page=$1&secondParam=$2 [NC,QSA,L]
于 2013-11-10T11:03:21.547 回答