【问题标题】:PHP and short URL [closed]PHP 和短 URL [关闭]
【发布时间】:2014-02-19 13:02:14
【问题描述】:

我有一个这样的网址:

http://www.domain.net/page.php?id=1254

我想以这种方式剪切我的网址(就像 Bitly 或 Goo.gl 这样的网址缩短器一样):

http://www.domain.net/1254

我不知道该怎么做(服务器设置?PHP 设置?),你能给我一些有用的参考吗?

问候。

【问题讨论】:

  • 如果您使用 Apache 作为 Web 服务器 - htaccess-guide.com
  • @kingkero 它缺乏足够的信息?这里的任何人都理解这个问题:-)

标签: php apache url


【解决方案1】:

使用 .htaccess

Options +SymLinksIfOwnerMatch
RewriteEngine on

RewriteBase /

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-l
RewriteRule ^([^/]+)/?$ page.php?id=$1 [L,QSA]

【讨论】:

  • 不会影响其他网址吗?喜欢http://www.domain.net/other.php?id=1?
  • 不,因为它的文件不同other.php。你只需要将 page.php 更改为 other.php 然后它也适用于 other.php
【解决方案2】:

您需要mod_rewrite 来通过 apache 替换 url

此处的文档:http://httpd.apache.org/docs/current/mod/mod_rewrite.html

【讨论】:

    猜你喜欢
    • 2015-12-28
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多