首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >根据输入的网址对不同文件的.htaccess

根据输入的网址对不同文件的.htaccess
EN

Stack Overflow用户
提问于 2015-01-25 23:06:15
回答 1查看 49关注 0票数 1

我正在尝试创建一个配置文件页和一个编辑配置文件页面。配置文件页面运行良好,URL存储在数据库中。它的工作方式如下:

  1. 用户输入网址(localhost/postin'/profiles/username)
  2. 一旦输入URL,.htaccess文件将重定向到profile.php文件,其中显示配置文件信息。

上面的操作非常好,.htaccess文件如下所示:

代码语言:javascript
复制
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

代码语言:javascript
复制
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:

代码语言:javascript
复制
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/usernamelocalhost/postin'/profiles/edit/username时,不管发生什么事情,它总是会到达localhost/postin'/profiles/username .有什么想法吗?:谢谢

固定

代码语言:javascript
复制
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]
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2015-01-25 23:43:04

您可以在您的:localhost/postin'/profiles/.htaccess中使用它:

代码语言:javascript
复制
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

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/28142644

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档