drq1257 2013-04-04 19:31 采纳率: 0%
浏览 106
已采纳

mod_rewrite隐藏文件扩展名

Options +FollowSymLinks 
RewriteEngine on

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*) /files.php?q=$1

RewriteCond %{HTTP_HOST} ^mysite.com
RewriteRule (.*) http://m.mysite.com/$1 [R=301,L]

AddHandler application/x-httpd-php5 .html .htm .txt .php

my .htaccess uses the main "files.php" for all requests. in my files.php i have some code in it that includes hrefs which looks like this:

/people/john --> when a person clicks on this, it should go to: people.php?q=john however, my .htaccess is not redirecting when person clicks on this /people/john. btw, the url should always say /people/john NOT people.php?q=john even though that is what is happening behind the scenes.

Just wanted to say, i have

/city/newyork --> city.php?q=newyork
/country/australia --> country.php?q=australia 

I have been struggling and searching here to find exactly, but still no luck. i appreciate all the responses.

  • 写回答

4条回答 默认 最新

  • doumeikuan6834 2013-04-04 20:38
    关注

    Based on your examples, you've got url's like this:

    /city/newyork, where city is the php file to call with parameter newyork
    

    If that's what you want, try this: Options +FollowSymLinks RewriteEngine on

    # Rewrite /city/newyork to city.php?q=newyork
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule ^(.*)/(.*) /$1.php?q=$2 [L]
    
    # Rewrite all urls without a second / to files.php?q=$1
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule ^(.*) /files.php?q=$1 [L]
    
    RewriteCond %{HTTP_HOST} ^mysite.com
    RewriteRule (.*) http://m.mysite.com/$1 [R=301,L]
    
    AddHandler application/x-httpd-php5 .html .htm .txt .php
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(3条)

报告相同问题?

悬赏问题

  • ¥100 连续两帧图像高速减法
  • ¥15 组策略中的计算机配置策略无法下发
  • ¥15 如何绘制动力学系统的相图
  • ¥15 对接wps接口实现获取元数据
  • ¥20 给自己本科IT专业毕业的妹m找个实习工作
  • ¥15 用友U8:向一个无法连接的网络尝试了一个套接字操作,如何解决?
  • ¥30 我的代码按理说完成了模型的搭建、训练、验证测试等工作(标签-网络|关键词-变化检测)
  • ¥50 mac mini外接显示器 画质字体模糊
  • ¥15 TLS1.2协议通信解密
  • ¥40 图书信息管理系统程序编写