dsomm80482 2014-05-05 13:16
浏览 31
已采纳

从GET重写动态URL

I want to rewrite my URLs which are based upon directories I have My directories look like this:

index.php
galleries
   -Party Weekend
       -2014
          -Bunchofimages.png
   -Other pics
       -Pictures.png

And the urls look like:

example.com/?f=/Party%20Weekend/2014

And I was looking for something like

example.com/Party-Weekend/2014

(Can be a dash or a + sign, doesn't really matter)

(Using .htaccess seems like the best option but I have no experience with .htaccess at all)

Also do I need to customize every single folder in the rewrite engine or can this be done dynamicly? (So I don't need to make a new rule for every folder I create)

I tried this but doesn't rewrite anything at all

RewriteEngine On 
RewriteRule ^([^/]*)/$ /?f=$1 [L]

Am I doing something wrong here?

  • 写回答

2条回答 默认 最新

  • dongnu4254 2014-05-05 14:18
    关注

    Try something like:

    RewriteEngine On
    
    RewriteCond %{THE_REQUEST} \ /+\?f=([^\ &]+)
    RewriteRule ^ /%1? [L,R]
    
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteCond %{DOCUMENT_ROOT}/galleries%{REQUEST_URI} -d
    RewriteRule ^(.*)$ /?f=$1 [L]
    

    There may be some encoding issues related to the spaces in your folder names, so you may either need some combination of the NE or B flags in side the brackets.

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

报告相同问题?

悬赏问题

  • ¥15 关于#matlab#的问题:在模糊控制器中选出线路信息,在simulink中根据线路信息生成速度时间目标曲线(初速度为20m/s,15秒后减为0的速度时间图像)我想问线路信息是什么
  • ¥15 banner广告展示设置多少时间不怎么会消耗用户价值
  • ¥16 mybatis的代理对象无法通过@Autowired装填
  • ¥15 可见光定位matlab仿真
  • ¥15 arduino 四自由度机械臂
  • ¥15 wordpress 产品图片 GIF 没法显示
  • ¥15 求三国群英传pl国战时间的修改方法
  • ¥15 matlab代码代写,需写出详细代码,代价私
  • ¥15 ROS系统搭建请教(跨境电商用途)
  • ¥15 AIC3204的示例代码有吗,想用AIC3204测量血氧,找不到相关的代码。