最后斜线后忽略URL最后一个字符串 [英] Ignore last string in URL after the last slash

查看:115
本文介绍了最后斜线后忽略URL最后一个字符串的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

例如:当 www.website.com/site/blue 用户类型,我希望他们去 www.website。在Web浏览器中的COM /网站/的index.php 。这样做的原因是,我想用PHP来抓住从URL蓝色,并将其放在 www.website.com/site/index.php

for example: when a user types in www.website.com/site/blue, I want them to go to www.website.com/site/index.php in the web browser. The reason for this is that I want to use php to grab blue from the URL and place it in www.website.com/site/index.php

所以,当有人类型 www.website.com/site/blue ...他们应该看到你好蓝色! www.website.com/site/index.php

So when someone types in www.website.com/site/blue ... they should see "Hello blue!!!" in www.website.com/site/index.php

推荐答案

这听起来像你需要使用一个htaccess文件和Apache的mod_rewrite。如果你被允许这样做你的服务器上,创建一个名为的.htaccess 文件中的网​​站目录。

It sounds like you need to use an htaccess file and Apache's mod_rewrite. If you are allowed to do this on your server, make a file called .htaccess in the site directory.

RewriteEngine on
RewriteRule ^(.*)$ index.php?color=$1

这将重写每一个请求作为查询字符串的index.php 为您解析。

That will rewrite every request as a query string to index.php for you to parse.

这篇关于最后斜线后忽略URL最后一个字符串的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆