2016-05-14 117 views
-1

重定向如果url包含特定单词而不更改它。重定向如果url包含单词而不更改url使用htaccess

如:http://localhost/APIs/student

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

我试过很多东西波纹管给他们的一个:

RewriteEngine on 
RewriteCond %{QUERY_STRING} ^[A-Z]{10,}\s/+index\.php\?page=([^\s&]+) [NC] 
RewriteRule^/%1? [R=301,L] 
RewriteRule ^([a-z0-9-]+)/?$ /APIs/index.php?page=$1-10 [QSA,L,NC] 

,如果我在通过多个参数上面的代码中失败链接后斜杠。

+1

提供更多信息。 – hjpotter92

+0

如果我通过“http:// localhost/APIs/student/dd/dd”,它会重定向到404页面。我想,如果有的话。参数在API中传递后,它应该重定向到index.php – Prerna

+0

“.htaccess”文件位于何处? – hjpotter92

回答

0

下面是规则

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

如果你请求

http://localhost/APIs/student/test 

你会被内部重定向到(你会看到与上述相同的URL)

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

index.php文件使用$_GET["page"]得到student/test,你可以决定什么在此基础上显示在页面中。

+0

不幸的是它不工作Rijul。 – Prerna

+0

创建一个名为'index.php'的php文件,代码为'<?php echo $ _GET [“page”]; ?>并将其放在'http:// localhost/APIs /'目录并从浏览器请求'http:// localhost/APis/student/test'。该页面应该显示'学生/测试'。告诉我浏览器在说什么。 –

+0

我已经更新了答案,请检查它。 –