douyin8813 2012-06-24 18:32
浏览 47
已采纳

重写URL .htaccess,mod_rewrite - “找不到目录”

I'm rewriting urls so my member pages - domain.com/profile.php?id=123 becomes domain.com/user/John

If somebody try to reach domain.com/user, the web browser says directory not found. Is there a way to make this directory "real", without adding the folder and an index file? In the .htaccess file?

When I call some scripts firebug will warn me about that the directory doesn't exists as well.

Here's the rewrite rule and entire .htaccess-file:

<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteCond %{HTTP_HOST} !^www\.domain\.com [NC]
RewriteRule ^(.*)$ http://www.domain.com/$1 [L,R=301]
</IfModule>

RewriteRule ^user/([^/\.]+)/?$ profile.php?username=$1 [L]
  • 写回答

3条回答 默认 最新

  • douxing5598 2012-06-24 19:29
    关注

    "What should be rendered if user/ is submitted without a username following it?"

    Doesn't matter really. Back to root I guess.

    Then write a rule specifically for that:

    RewriteRule ^user/?$ / [L]
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(2条)

报告相同问题?

悬赏问题

  • ¥20 西门子S7-Graph,S7-300,梯形图
  • ¥50 用易语言http 访问不了网页
  • ¥50 safari浏览器fetch提交数据后数据丢失问题
  • ¥15 matlab不知道怎么改,求解答!!
  • ¥15 永磁直线电机的电流环pi调不出来
  • ¥15 用stata实现聚类的代码
  • ¥15 请问paddlehub能支持移动端开发吗?在Android studio上该如何部署?
  • ¥20 docker里部署springboot项目,访问不到扬声器
  • ¥15 netty整合springboot之后自动重连失效
  • ¥15 悬赏!微信开发者工具报错,求帮改