dongyou5271 2013-12-05 23:02
浏览 30

URL,没有扩展名的页面名称[重复]

This question already has an answer here:

I am trying to have my pages accessible with example.com/about, example.com/contacts instead of example.com/about.php & example.com/contact.php

I am not sure how this is done, but I was able to do it by creating link

<a href='site.com/about'> about </a>

And I have my index.php set as

$URI = $_SERVER['REQUEST_URI']; 
switch($URI){
  case '/about';
    include 'about.php';
    break; 
  case '/contact';
    include 'contact.php';
    break; 
  //...
}

Now, asking if this is a good way will have my thread closed as objective question. But I would like to know, how it is done, or more accurately, how everyone does it.

</div>
  • 写回答

1条回答 默认 最新

  • doushan7997 2013-12-05 23:09
    关注

    I use this in .htaccess

    /blah goes to /blah.php etc. It's not slower than loading a php page, and then loading in there.

    RewriteEngine On
    # Redirect external .php requests to extensionless url
    RewriteCond %{THE_REQUEST} ^(.+)\.php([#?][^\ ]*)?\ HTTP/
    RewriteRule ^(.+)\.php$ http://WEBSITE.com/$1 [R=301,L]
    
    # Resolve .php file for extensionless php urls
    RewriteRule ^([^/.]+)$ $1.php [L]
    
    评论

报告相同问题?

悬赏问题

  • ¥15 随身WiFi网络灯亮但是没有网络,如何解决?
  • ¥15 gdf格式的脑电数据如何处理matlab
  • ¥20 重新写的代码替换了之后运行hbuliderx就这样了
  • ¥100 监控抖音用户作品更新可以微信公众号提醒
  • ¥15 UE5 如何可以不渲染HDRIBackdrop背景
  • ¥70 2048小游戏毕设项目
  • ¥20 mysql架构,按照姓名分表
  • ¥15 MATLAB实现区间[a,b]上的Gauss-Legendre积分
  • ¥15 delphi webbrowser组件网页下拉菜单自动选择问题
  • ¥15 linux驱动,linux应用,多线程