1

我目前正在使用 .htaccess 重写我的网址

example.com/mixtape.php?id=(WHATEVER #)
...到...
example.com/m/(WHATEVER #)

我用来完成的代码如下:

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^m\/([^/\.]+)/?$ mixtape.php?mixid=$1 [L]

我想要实现的下一件事,在一个干净的问题上,是重写我的

example.com/edit-mixtape.php?id=(WHATEVER #)
...到...
example.com/m/(WHATEVER #)/edit


编辑: “WHATEVER #”是我正在编辑的 Mixtape 的 ID。通常我会使用“$_GET['id']”来查看我指的是什么混音带,然后我会获取与该数字相关的所有内容。

有没有人可以帮助我成功编写一个合适的重写模块?

4

2 回答 2

2

Based on your comment, I would change your original rule as well to allow only for numbers:

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^m/(\d+)/edit/?$ edit-mixtape.php?mixid=$1 [L]

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^m/(\d+)/?$ mixtape.php?mixid=$1 [L]

By the way, I would probably use a general rule and write both urls to the same php file and handle the action in the controller.

于 2012-09-11T01:37:04.427 回答
1

You can use the same rules that you had before but just append an edit to the regular expression:

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^m\/([^/\.]+)/edit/?$ edit-mixtape.php?mixid=$1 [L]

Note that your original rules have the query string mixid= while your examples say id=.

于 2012-09-11T01:37:11.387 回答