php - .htaccess 多 URL 重写

标签 php .htaccess url url-rewriting rewrite

我有这条规则:

RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ profil.php?upime=$1

它正在运行。现在我想知道如何重写另一个页面的 URL:

RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ profil.php?upime=$1
RewriteRule ^(.*)$ novica.php?nid=$2 - I did this, but is not working.

我该怎么做才能将这两个规则都放在一个 .htaccess 文件中?

最佳答案

你不能像在你的例子中那样做,因为你正在重写所有内容:^(.*)$

如果您想要两个不同的规则,则需要选择要将哪些 url 写入哪个最终目的地。

将以不同字符串开头的不同 url 重写到不同目的地的示例:

RewriteEngine On

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^starts_with_this(.*)$ profil.php?upime=$1

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^starts_with_something_else(.*)$ novica.php?nid=$1

关于php - .htaccess 多 URL 重写,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12860695/

相关文章:

python - django:管理网址中的 Nonelogout

php - 重新排列数组

php - MySQL - null = 0 的问题

php - 单击时使用 PHP 生成的表行的 ID 更新 AJAX 请求变量

apache - htaccess 拒绝所有获取 apache 服务器测试页面

css - codeigniter Controller 和 controller/之间有什么区别?

database - 从 URL 中删除结尾的斜杠总是安全的吗?

php - Symfony2命令行生成全局文件夹下的twig模板

.htaccess - 如何使用 .htaccess + 限制访问隐藏文件扩展名

wordpress - mod deflate 不压缩根目录的子目录