dongque1646 2011-06-01 16:22
浏览 31
已采纳

php和url重写

so I was wondering if something like this is at all possible.

I was hoping to change /?directory=$variable to something like /$variable

An actual example might be easier to understand. So I want <a href='/{$variable}' > to really be /?directory=$variable or in url rewite terms i guess /?page=$1

I hope this makes sense. I am really no good with rewriting. Is this even possible? I was hoping to exclude index.php on that. however if that cannot be done, and example with index.php?ect.. will work. Thanks!

  • 写回答

4条回答 默认 最新

  • douqun1977 2011-06-01 16:25
    关注

    Yes it's possibile if your server/hosting supports it you can do it by creating an .htaccess file with:

    RewriteEngine On
    RewriteRule ^/(.+)$ /?directory=$1 [L]
    

    If you want to allow other directories/files to get accessed normally you should do something like:

    RewriteRule ^/([a-z]+)$ /?directory=$1 [L]
    

    This will capture any subdirectory like /abc but not /css.css or /customsub/other file

    Welcome to the world of SEO optimizer lol.

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

报告相同问题?

悬赏问题

  • ¥40 复杂的限制性的商函数处理
  • ¥15 程序不包含适用于入口点的静态Main方法
  • ¥15 素材场景中光线烘焙后灯光失效
  • ¥15 请教一下各位,为什么我这个没有实现模拟点击
  • ¥15 执行 virtuoso 命令后,界面没有,cadence 启动不起来
  • ¥50 comfyui下连接animatediff节点生成视频质量非常差的原因
  • ¥20 有关区间dp的问题求解
  • ¥15 多电路系统共用电源的串扰问题
  • ¥15 slam rangenet++配置
  • ¥15 有没有研究水声通信方面的帮我改俩matlab代码