dpxnrx11199 2011-02-05 23:15
浏览 33

URL重写以删除参数


I'm working on a site where all the pages are actually index.php + a 'name' parameter that is analyzed and loads the appropriate template and content.
the homepage url is:
http://www.some_site.com/?page=homepage

1. i was asked to "change" the homepage url to:
http://www.some_site.com
can i use url rewite and htaccess for that and if so, what should i write there?

working on my local machine, i tried this code (mode rewrite is enabled):

<IfModule mod_rewrite.c>
Options +FollowSymLinks
RewriteEngine On
RewriteRule /index.php /index.php?page=homepage
</IfModule>

i would still need the 'name' parameter to be available to the php code of course, so i can load the template and css files.

2. it would be nice for other pages (not homepage) to be converted from (example)
http://www.some_site.com/?page=products
to:
http://www.some_site.com/products
this is less crucial.

thanx in advance and have a nice day :-)

  • 写回答

2条回答 默认 最新

  • dsb53973 2011-02-05 23:18
    关注

    You don't need a rewrite rule at all. Just change your index.php file to show the homepage when there is no page variable at all.

    if (!isset($_GET['page'])) {
        $_GET['page'] = 'homepage';
    }
    

    For educational purposes, the rewrite rule:

    RewriteRule /$ index.php?page=homepage [L]
    

    That is, the URI to match is just the slash (the URI starts after your domain in the URL). The $ means that there should be no characters after the slash.

    As for products and such, assuming single words made of only letters:

    RewriteRule /([a-zA-Z]+)$ index.php?page=$1 [L]
    
    评论

报告相同问题?

悬赏问题

  • ¥50 如何用脚本实现输入法的热键设置
  • ¥20 我想使用一些网络协议或者部分协议也行,主要想实现类似于traceroute的一定步长内的路由拓扑功能
  • ¥30 深度学习,前后端连接
  • ¥15 孟德尔随机化结果不一致
  • ¥15 apm2.8飞控罗盘bad health,加速度计校准失败
  • ¥15 求解O-S方程的特征值问题给出边界层布拉休斯平行流的中性曲线
  • ¥15 谁有desed数据集呀
  • ¥20 手写数字识别运行c仿真时,程序报错错误代码sim211-100
  • ¥15 关于#hadoop#的问题
  • ¥15 (标签-Python|关键词-socket)