doubeiji2602 2015-04-19 18:42
浏览 55

php mvc中的虚荣配置文件网址无法正常工作

I am making a social networking site where I have created my own PHP mvc but I am having problems in url rewriting. My mvc works this way.

If this is the domain www.example.com/manage/posts/11111 , manage is the class, post is the method in that class & 1111 is a parameter.

The problem is that I cannot create vanity profile urls since they will not work. I want each user to have vanity profile url ie www.example.com/username but this will search for a class named username.

Kindly advise me on how

a) I can achieve vanity profile urls such as www.example.com/username without adding anything such as www.example.com/users/username.

I know there a other PHP MVCs but I just want to use my own

This is my current htaccess code::

<IfModule mod_rewrite.c>
    RewriteEngine On
    RewriteBase /
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule ^(.*)/?$  index.php?ref_url=$1 [NC,L,QSA]
</IfModule>
  • 写回答

2条回答 默认 最新

  • dongluedeng1524 2015-04-19 18:55
    关注

    I don't know why all people try to build their own frameworks there are so many really good frameworks that have a look at security and many more. But ok i think your problem is your rewrite rule.

    RewriteRule ^(.*)$  index.php?ref_url=$1 [NC,L,QSA]
    

    Normally you should rewrite all your input to a given file and parse the url and call the controller you need. To get a better understanding take a look at the Symfony2 Routing component.

    http://symfony.com/doc/current/components/routing/introduction.html

    评论

报告相同问题?

悬赏问题

  • ¥20 完全没有学习过GAN,看了CSDN的一篇文章,里面有代码但是完全不知道如何操作
  • ¥15 使用ue5插件narrative时如何切换关卡也保存叙事任务记录
  • ¥20 软件测试决策法疑问求解答
  • ¥15 win11 23H2删除推荐的项目,支持注册表等
  • ¥15 matlab 用yalmip搭建模型,cplex求解,线性化处理的方法
  • ¥15 qt6.6.3 基于百度云的语音识别 不会改
  • ¥15 关于#目标检测#的问题:大概就是类似后台自动检测某下架商品的库存,在他监测到该商品上架并且可以购买的瞬间点击立即购买下单
  • ¥15 神经网络怎么把隐含层变量融合到损失函数中?
  • ¥15 lingo18勾选global solver求解使用的算法
  • ¥15 全部备份安卓app数据包括密码,可以复制到另一手机上运行