如果网址包含单词而不使用htaccess更改网址,则重定向

时间:2016-05-14 20:17:10

标签: php apache .htaccess redirect mod-rewrite

重定向如果网址包含特定字词而不更改它。

例如:http://localhost/APIs/student

应重定向到“http://localhost/APIs/

我尝试了很多其中的一件事,如下:

{{1}}
如果我在斜杠后传递链接中的多个参数,

上面的代码段会失败。

1 个答案:

答案 0 :(得分:0)

以下是规则

RewriteEngine on
RewriteRule ^APIs/(.*)$ APIs/index.php?page=$1 [NC,END]

如果您要求

http://localhost/APIs/student/test

您将在内部重定向到(您将看到与上面相同的网址)

http://localhost/APIs/index.php?page=student/test

index.php文件中使用$_GET["page"]获取student/test,您可以根据此决定在页面中显示的内容。

相关问题