我正在尝试创建一个配置文件页和一个编辑配置文件页面。配置文件页面运行良好,URL存储在数据库中。它的工作方式如下:
localhost/postin'/profiles/username).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>但是当我localhost/postin'/profiles/edit/username?时会发生什么?它不适用于我当前的.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。所以"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>当我尝试URLS localhost/postin'/profiles/username和localhost/postin'/profiles/edit/username时,不管发生什么事情,它总是会到达localhost/postin'/profiles/username .有什么想法吗?:谢谢
固定
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]发布于 2015-01-25 23:43:04
您可以在您的: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
https://stackoverflow.com/questions/28142644
复制相似问题