drrkgbm6851 2013-02-12 20:00
浏览 42
已采纳

.htaccess条件重写和文件结构[重复]

This question already has an answer here:

To break it down, this is how my sitemap looks like.

http://website.com/home
http://website.com/contact
http://website.com/support

With my index.php handler handling the GET statement index.php?home, index.php?contact, and index.php?support

Currently, my .htaccess looks like this:

RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI}  /([^/]+)/?$  [NC]
RewriteRule .*   index.php?%1  [L]

So far this works great, however it's limited. I'm integrating a mini blog I designed in PHP that would accept query string to look as so:

http://site.com/blog.php?y=2013&m=02&d=12&title=welcome-to-site-blog

Now, I would like to keep the sites root file structure AND also integrate a blogging file structure. Hopefully to look like this:

http://site.com/2013/02/12/welcome-to-site-blog

Any help would be great. I understand that conditional statements will be required, but I have little to no experience with htaccess.

Thanks in advance, Chris

</div>
  • 写回答

1条回答 默认 最新

  • dongzou7134 2013-02-12 20:51
    关注

    You may try this:

    Options +FollowSymlinks
    RewriteEngine On
    RewriteBase /
    RewriteCond %{REQUEST_URI}   !blog\.php                           [NC]
    RewriteCond %{REQUEST_URI}   ^/([^/]+)/([^/]+)/([^/]+)/([^/]+)/?  [NC]
    RewriteRule .  blog.php?key1=%1&key2=%2&key3=%3&key4=%4         [L,NC]
    

    Maps silently

    http://site.com/var1/var2/var3/var4

    To:

    http://site.com/blog.php?key1=var1&key2=var2&key3=var3&key4=var4

    All varN strings are assumed to be variable while the script name blog.php is fixed but can be any name. Replace all instances in the rule set if changed.

    For permanent and visible redirection, replace [L,NC] with [R=301,L,NC].

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥100 set_link_state
  • ¥15 虚幻5 UE美术毛发渲染
  • ¥15 CVRP 图论 物流运输优化
  • ¥15 Tableau online 嵌入ppt失败
  • ¥100 支付宝网页转账系统不识别账号
  • ¥15 基于单片机的靶位控制系统
  • ¥15 真我手机蓝牙传输进度消息被关闭了,怎么打开?(关键词-消息通知)
  • ¥15 装 pytorch 的时候出了好多问题,遇到这种情况怎么处理?
  • ¥20 IOS游览器某宝手机网页版自动立即购买JavaScript脚本
  • ¥15 手机接入宽带网线,如何释放宽带全部速度