php url 缩短 [英] php url shortening
问题描述
好吧,我想这是一个有点笼统的问题,而不是一个问题.
Ok i guess this is a bit of a general question really as opposed to a problem.
我正在构建一个系统,让用户可以在其他网站上共享他们的个人资料,所以我想知道是否可以缩短实际网址,该网址将提供指向他们个人资料的链接,类似于这样的链接,www.somedomain.com/users/profile.php?user=myusername
简单地剪掉用户文件夹和个人资料页面等等:www.somedomain.com/myusername
I am building a system where users can share their profile on other websites so i am wondering is it possible to shorten the actual url which would provide a link to their profile which would be something like this, www.somedomain.com/users/profile.php?user=myusername
to simply cut out the users folder and the profile page and so something like this: www.somedomain.com/myusername
我见过很多 url 缩短脚本,但他们似乎没有这样做,任何建议或建议将不胜感激.
I have seen lots of url shortening scripts but they don't seem to do this, any suggestions or advice would be appreciated.
谢谢
推荐答案
您要查找的内容称为 URL 重写,可以使用 Apache 的 mod_rewrite.您可以将一个名为 .htaccess 的文件放在您的 Web 根目录中,它会包含如下代码段:
What you're looking for is called URL rewriting and can be done using Apache's mod_rewrite. You would place a file called .htaccess in your root web directory and it would contain a snippet like this:
RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule /(.*) /users/profile.php?user=$1
这篇关于php url 缩短的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!