微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

Apache 2中的URL缩短

如何解决Apache 2中的URL缩短

| 我的网站首页为as0ѭ 现在我想将
www.mysite.com/x2312d
指向
/var/www/mysite/app/pass.PHP?id=x2312d
我该怎么做呢? 我应该在哪里创建
.htaccess
文件,该文件内容是什么?     

解决方法

在你的根
/var/www
.htaccess
RewriteEngine On
RewriteBase /
RewriteCond %{SCRIPT_FILENAME} !-d
RewriteRule ^([^\\.]+)$ /app/pass.php?id=$1 [NC,L]
    ,将.htaccess文件放在/ var / www / mysite / app /中。我假设您的docroot是/ var / www / mysite / 确保apache 2已启用重写模块 .htaccess:
RewriteEngine On

#allows you to still access static items in this dir
RewriteCond %{REQUEST_URI} !\\.(php|css|js|gif|png|jpe?g)$

#sent it all to pass script
RewriteRule (.*)$ pass.php [L]
我喜欢这种方法,假设pass是某种控制器。我的rest api控制器从$ _SERVER全局变量手动解析/ x23123d,但是您可以使用其他重写器将其放在$ _GET / $ _ REQUEST [\'id \']全局变量中。 像这样的东西:
RewriteRule ^app/(.+)$ app/pass.php?id=$1 [PT,L,QSA]
良好参考:http://httpd.apache.org/docs/2.0/misc/rewriteguide.html http://httpd.apache.org/docs/2.0/mod/mod_rewrite.html#rewriterule 编辑:几乎忘记了,不要忘记也处理斜杠。     

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。