doucha7329 2017-10-30 09:30
浏览 51
已采纳

如何在使用htaccess和php重写用户配置文件页面时允许使用dot

I have encountered a problem in trying to rewrite users profile page with usernames containing a full stop.

First of all, i applied this rewrite rule to my htaccess file;

RewriteEngine On
RewriteCond %{SCRIPT_FILENAME} !-d
RewriteRule ^([a-zA-Z0-9_]+)$ profile.php?tg_u=$1 [NC,L]
RewriteRule ^([^.]+)$ $1.php [NC,L]

actually, the rewrite rule worked when accessing users with username containing only letters and username containing a number and underscore(_) but when trying to access users with username such as user.name i do get a 404 page error, i tried changing previous preg_match to this preg_match(a-zA-Z0-9_.) and later to this preg_match(a-zA-Z0-9_.) on my htaccess (rewrite rule) but i noticed that when i want to access my site in localhost, the profile.php page is been shown as index page, i later then use this preg_match(a-zA-Z0-9.) on my htaccess file but still encounter the same problem.
I will be very grateful to know why i encounter this problem and also how to fix it.

  • 写回答

1条回答 默认 最新

  • dsgm5631 2017-10-30 12:22
    关注

    You can use:

    RewriteEngine On
    RewriteCond %{SCRIPT_FILENAME} !-d
    RewriteCond %{SCRIPT_FILENAME} !-f
    RewriteRule ^([a-zA-Z0-9_.]+)$ profile.php?tg_u=$1 [NC,L]
    RewriteCond %{DOCUMENT_ROOT}/$1.php -f
    RewriteRule ^([^.]+)$ $1.php [NC,L]
    

    -d If the request is not a directory, and -f not a valid file name.
    And I added a test not to rewrite to php a page that does not exist.

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

报告相同问题?

悬赏问题

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