【发布时间】:2018-09-25 23:28:24
【问题描述】:
我搜索了许多类似的问题,但找不到答案。我有一个有用户的 php 网站,我想创建用户个人资料页面。
现在,它是这样工作的:
https://example.com/profile?userid=user_id_here
但我希望它像这样工作:
https://example.com/profile/user_id_here
当用户点击他们的个人资料网址时,即:
https://example.com/profile/user_id_here
我希望页面静默调用这个 url:
https://example.com/profile?userid=user_id_here
因此用户将始终看到友好的 url,不带问号和 userid= 部分。
我不想将此页面 (https://example.com/profile?userid=user_id_here) 重定向到此页面 (https://example.com/profile/user_id_here),因为用户不会看到此页面 (https://example.com/profile?userid=user_id_here)。
我只想让 profile.php 静默调用特定的漂亮 url。
我当前的重写规则如下,我希望新规则添加以下规则:
RewriteEngine On
# match any URL with www and rewrite it to https without the www
RewriteCond %{HTTP_HOST} ^(www\.)(.*) [NC]
RewriteRule (.*) https://%2%{REQUEST_URI} [L,R=301]
# match urls that are non https (without the www)
RewriteCond %{HTTPS} off
RewriteCond %{HTTP_HOST} !^(www\.)(.*) [NC]
RewriteRule (.*) https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
#remove .php
RewriteRule ^(.+)\.php$ /$1 [R,L]
RewriteCond %{REQUEST_FILENAME}.php -f
RewriteRule ^(.*?)/?$ /$1.php [NC,END]
我为此花了大约 2 天的时间,但找不到解决方案。感谢您对解释规则所做的任何帮助。先感谢您。
【问题讨论】:
标签: php regex apache .htaccess