0

我正在尝试为我的动态生成的 PHP 站点重写 URL。

index.php我使用以下 GET加载新模板:

localhost/dmk/?req=signin
localhost/dmk/?req=useraccount

我希望这些链接显示为:

localhost/dmk/signin
localhost/dmk/useraccount

但是对于我的生活,我无法弄清楚如何做到这一点。我尝试的一切要么产生 500 内部服务器错误,要么根本没有效果。

我一定错过了RewriteRule

4

2 回答 2

1

Try this

Options +FollowSymLinks -MultiViews
RewriteEngine on
RewriteBase /

RewriteCond %{REQUEST_FILENAME} !-d # not a dir
RewriteCond %{REQUEST_FILENAME} !-f # not a file
RewriteRule ^dmk/(.+)$ dmk/?req=$1 [NC,QSA,L]

This would redirect any URL like /dmk/page that does not conflict with an existing file or directory to /dmk/?req=page. I'm assuming your index.php is in /dmk directory.

于 2013-08-24T08:23:33.880 回答
1

You should read some documentation in this direction. I know it's a bit frustrating at first to write the rules, but it gets easier. You need to learn regular expressions to write the rules (you can start here: http://www.regular-expressions.info/)

As for the rules you need, they go like this:

RewriteEngine On

RewriteRule ^signin$ index.php?req=signin [L,QSA]
RewriteRule ^useraccount$ index.php?req=useraccount [L,QSA]

or

RewriteRule ^(signin|useraccount)$ index.php?res=$1 [L,QSA]

You can paste the rules you have used, maybe someone will explain you what you did wrong.

于 2013-08-24T08:23:40.743 回答