【问题标题】:Subfolder .htaccess not found未找到子文件夹 .htaccess
【发布时间】:2015-07-08 15:46:32
【问题描述】:

嗨朋友们,我收到了这个错误,请告诉我如何解决这个错误。我的 htaccess 文件的 htaccess 是这样的:

#Options +FollowSymLinks -MultiViews
#RewriteEngine On
#RewriteBase /

RewriteCond %{REQUEST_FILENAME} -f [OR]
RewriteCond %{REQUEST_FILENAME} -d
RewriteCond %{REQUEST_FILENAME}\.php -f
RewriteRule ^ - [L]

RewriteRule ^friends/([\w-]+)/?$ /friends.php?username=$1 [L,QSA]
RewriteRule ^followers/([\w-]+)/?$ /followers.php?username=$1 [L,QSA]
RewriteRule ^settings/([\w-]+)/?$ /settings.php?username=$1 [L,QSA]

RewriteRule ^messages/([\w-]+)/?$ chat.php?message_username=$1 [L,QSA]
RewriteRule ^following/([\w-]+)/?$ following.php?username=$1 [L,QSA]
RewriteRule ^following/([\w-]+)/([0-9]+)/?$ following.php?username=$1&page=$2 [L,QSA]
RewriteRule ^followers/([\w-]+)/?$ followers.php?username=$1 [L,QSA]
RewriteRule ^followers/([\w-]+)/([0-9]+)/?$ followers.php?username=$1&tpage=$2 [L,QSA]
RewriteRule ^photos/([\w-]+)/?$ userphotos.php?username=$1&page=$2 [L,QSA]
RewriteRule ^(.*/([a-zA-Z0-9_-]+)|([a-zA-Z0-9_-]+))$ profile.php?username=$1 [L,QSA]

未找到

在此服务器上找不到请求的 URL /profile/following/demo。

prototype.kofendurance.com 端口 80 上的 Apache/2.2.15 (CentOS) 服务器

我也得到同样的错误所有 htaccess RewriteRule。

【问题讨论】:

  • 你应该取消第一行的注释,至少RewriteEngine OnRewriteBase /(只需删除行首的#)
  • @devsymediane 然后我收到此错误:Not Found The requested URL /following.php was not found on this server.
  • 你的最后一条规则是启动并重定向到/profile.php?username=profile/following/demo
  • 您的文件(如following.php)是否在子文件夹中?如果是这种情况,您应该调整 RewriteBase(如 RewriteBase /myfolder
  • @devsymediane 感谢您的回答,但它无法正常工作,因为我没有以下文件夹。这是 .htaccess 设置。那么,如果它有效,那么我能为其他 RewriteRule 做什么?

标签: php regex apache .htaccess mod-rewrite


【解决方案1】:

您跳过文件或目录的第一条规则不正确,您需要取消注释开头的行:

Options +FollowSymLinks -MultiViews
RewriteEngine On
RewriteBase /profile/

# skip real files and directories from all the rules
RewriteCond %{REQUEST_FILENAME} -f [OR]
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^ - [L]

# rest of the rules

【讨论】:

  • 感谢您的回答,您能告诉我您的意思吗# skip real files and directories from all the rules
  • 这是同样的错误 Not Found 在此服务器上未找到请求的 URL /profile.php。因此,当我单击用户配置文件时出现此错误。其他 RewriteRule 也同样的错误。
  • .htaccess 文件在 www/profile/(这里) 完整的 url borwser 是:http://prototype.kofendurance.com/profile/demo
  • 非常感谢您提供的最佳帮助。你是 StackOverflow 上最好的 ;)
  • 亲爱的 settings.php 不能使用 .htaccess 只有那个页面给我 404 页面未找到。 http://prototype.kofendurance.com/profile/settings/demo
猜你喜欢
  • 2014-06-23
  • 2011-02-20
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2012-12-12
  • 1970-01-01
  • 1970-01-01
  • 2016-04-23
相关资源
最近更新 更多