douliao8402 2014-05-28 08:50
浏览 100
已采纳

ShortURL之类的URL分析[重复]

This question already has an answer here:

i am trying to implement a shortURL feature to my website. Calling the URL http://example.com/T35T should redirect the user to a specific website. My problem is getting the keyword behind the top level domain. By calling the URL, the webserver tries to locate the folder T35T and throws an error.

How can i stop the server (apache) from searching for the folder, so i can read the URL via PHP and redirect the user correctly.

Thanks you for your answers!

Greetings

</div>
  • 写回答

2条回答 默认 最新

  • duansen6750 2014-05-28 09:44
    关注

    The question URL rewriting with PHP is more or less what you need (or this one How can I display SEO friendly URLs using mod_rewrite?).

    What you need is to tell apache to convert this URL to a page that you can manage.

    From the accepted answer by Niels Keurentjes (modified to your needs):

    Add a file called .htaccess in your root folder, and add something like this:

    RewriteEngine on
    RewriteRule ^/([a-zA-Z0-9]+)$ /redirect.php?id=$1
    

    This will tell Apache to enable mod_rewrite for this folder, and if it gets asked a URL matching the regular expression it rewrites it internally to what you want, without the end user seeing it.

    Then in the page redirect.php you can do a HTTP redirect based on the id.

    You can also see the official guide.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥50 用AT89C52单片机设计一个温度测量与控制电路
  • ¥15 无法import pycausal
  • ¥15 VS2022创建MVC framework提示:预安装的程序包具有对缺少的注册表值的引用
  • ¥15 weditor无法连接模拟器Local server not started, start with?
  • ¥20 6-3 String类定义
  • ¥15 嵌入式--定时器使用
  • ¥20 51单片机学习中的问题
  • ¥30 Windows Server 2016利用兩張網卡處理兩個不同網絡
  • ¥15 Python中knn问题
  • ¥15 使用C#,asp.net读取Excel文件并保存到Oracle数据库