我正在尝试制作个人资料页面和编辑个人资料页面。个人资料页面运行良好,URL 存储在数据库中。它的工作原理是这样的:
- 用户输入网址 (
localhost/postin'/profiles/username
) - 输入 URL 后,
.htaccess
文件将重定向到显示配置文件信息的profile.php
文件
上面效果很好,.htaccess文件看起来像这样:
Options +FollowSymLinks
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(['w.'@'''/-]+)$ profile.php?user=$1 [NC,L]
<Files .htaccess>
order allow,deny
deny from all
</Files>
但是当我本地主机/帖子/配置文件/编辑/用户名时会发生什么?它不适用于我当前的.htaccess
,因为它认为编辑是用户名的一部分,而实际上它只是另一个文件。我试了这个.htaccess
:
Options +FollowSymLinks
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(['w.'@'''/-]+)$ profile.php?user=$1 [NC,L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^edit/(['w.'@'''/-]+)$ /profile.php?user=$1 [NC,L]
<Files .htaccess>
order allow,deny
deny from all
</Files>
然而它似乎没有奏效! :(
所以这里有一个快速的例子,说明我希望它做什么。用户的用户名是 hawkeye
。所以"鹰眼"进入localhost/postin'/profiles/hawkeye
是为了获得他的个人资料。然后要编辑他的个人资料,他输入 localhost/postin'/profiles/edit/hawkeye
.
此文件的.htaccess
是什么样子的?谢谢!:)
更新
这是我正在使用的.htaccess:
Options +FollowSymLinks
RewriteEngine on
# skip all files and directories from rewrite rules below
RewriteCond %{REQUEST_FILENAME} -d [OR]
RewriteCond %{REQUEST_FILENAME} -f
RewriteRule ^ - [L]
RewriteRule ^edit/(['w.'@'''/-]+)$ editprofile.php?user=$1 [NC,L]
RewriteRule ^(['w.'@'''/-]+)$ profile.php?user=$1 [NC,L]
<Files .htaccess>
order allow,deny
deny from all
</Files>
当我尝试 URL localhost/postin'/profiles/username 和 localhost/postin'/profiles/edit/username 时,无论如何它总是转到 localhost/postin'/profiles/username ......有什么想法吗?:D谢谢
固定
Options +FollowSymLinks
RewriteEngine on
# skip all files and directories from rewrite rules below
RewriteCond %{REQUEST_FILENAME} -d [OR]
RewriteCond %{REQUEST_FILENAME} -f
RewriteRule ^ - [L]
RewriteRule ^edit/(['w.'@'''/-]+)$ editprofile.php?user=$1 [NC,L]
RewriteRule ^(['w.'@'''/-]+)$ profile.php?user=$1 [NC,L]
您可以在您的: localhost/postin'/profiles/.htaccess
:
Options +FollowSymLinks
RewriteEngine on
# skip all files and directories from rewrite rules below
RewriteCond %{REQUEST_FILENAME} -d [OR]
RewriteCond %{REQUEST_FILENAME} -f
RewriteRule ^ - [L]
RewriteRule ^edit/(['w.'@'''/-]+)$ editprofile.php?user=$1 [NC,L]
RewriteRule ^(['w.'@'''/-]+)$ profile.php?user=$1 [NC,L]
重定向profiles/username
-> profiles/profile.php?user=username
重定向profiles/edit/username
-> profiles/editprofile.php?user=username