Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/dart/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Apache 添加尾部斜杠和重定向301后的htaccess无限循环_Apache_.htaccess_Redirect - Fatal编程技术网

Apache 添加尾部斜杠和重定向301后的htaccess无限循环

Apache 添加尾部斜杠和重定向301后的htaccess无限循环,apache,.htaccess,redirect,Apache,.htaccess,Redirect,我的访问权限有问题。我想在我的URL中添加一个尾随斜杠。我目前正在当地发展。以下是htaccess: Options +FollowSymlinks RewriteEngine On #RewriteBase RewriteBase /balade-gourmande DirectoryIndex index.php # Add ending slash RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME}

我的访问权限有问题。我想在我的URL中添加一个尾随斜杠。我目前正在当地发展。以下是htaccess:

Options +FollowSymlinks
RewriteEngine On

#RewriteBase 
RewriteBase /balade-gourmande

DirectoryIndex index.php

# Add ending slash
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI} !(.*)/$
RewriteRule ^(.*)$ %{REQUEST_URI}/ [R=301,L] 


# Main pages
RewriteRule ^(.*)/(.*)/$                $2.php [L]
RewriteRule ^(.*)/$                 $1.php [L]
正如您所看到的,我的本地主机上有很多其他网站(为什么我有一个重写库)。所有my.php文件都在“balade gourmande”目录中。 我在balade gourmande文件夹中有一个index.php和一个yes.php文件

如果我尝试:

localhost/balade gourmande/>没关系,我登陆index.php

localhost/balade gourmande/yes->没关系,我登陆了yes.php

localhost/balade gourmande/yes/->没关系,我登陆了yes.php

问题是如果输入错误,例如: localhost/balade gourmande/where 它给我一个:localhost/balade gourmande/whatever.php.php.php.php.php.php.php.php.php.php.php.php.php.php.php.php.php.php.php.php/ 无限循环错误

有人能帮我吗?如果你需要更多的信息,我会尽力的

谢谢

**编辑: 这是根目录中的htaccess,而不是我的“balade gourmande/”:

htaccess

# ----------------------------------------------------------------------
# Start rewrite engine
# ----------------------------------------------------------------------

# Turning on the rewrite engine is necessary for the following rules and features.
# FollowSymLinks must be enabled for this to work.

<IfModule mod_rewrite.c>
 # Make sure directory listing is disabled
Options +FollowSymLinks -Indexes
RewriteEngine on

# Send request via index.php
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d


RewriteRule ^(.*)$ index.php/$1 [L]



</IfModule>
#----------------------------------------------------------------------
#启动重写引擎
# ----------------------------------------------------------------------
#打开重写引擎对于以下规则和功能是必需的。
#必须启用以下符号链接才能使其工作。
#确保目录列表已禁用
选项+FollowSymLinks-索引
重新启动发动机
#通过index.php发送请求
重写cond%{REQUEST_FILENAME}-F
重写cond%{REQUEST_FILENAME}-D
重写规则^(.*)$index.php/$1[L]

希望它对您有所帮助,我从来没有犯过错误

请将下面的两条规则#主页部分替换为以下规则:

DirectoryIndex index.php
ErrorDocument 404 /balade-gourmande/errorhandler.php
Options +FollowSymlinks -MultiViews
RewriteEngine On

# Add ending slash
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{THE_REQUEST} \s/+.*?[^/][\s?]
RewriteRule [^/]$ %{REQUEST_URI}/ [R=301,L]

RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{DOCUMENT_ROOT}/$1\.php -f [NC]
RewriteRule ^(.+?)/?$ /$1.php [L]

这是从我的现场网站完全工作的规则。确保它放在root.htaccess中,而不是子目录中。你好,anubhava,好的,如果你在一个实时网站上,但正如我所说,它在我的本地机器上,我希望它工作。它与实时网站或本地主机无关。规则也是如此。在您的本地主机上,将上述规则放在
DocumentRoot/.htaccess
file.:)中,它似乎有效。最后一件事,如果我将此htaccess放在本地主机文件夹(服务器的根目录)中,是否需要删除“balade gourmande”文件夹中的htaccess?***编辑:如果我想抛出一个“ErrorDocument404”行,我必须如何编写它?“rewritebase/balade gourmande”怎么办?我必须改为写“rewritebase/”吗?谢谢你的帮助!您是否在
/balade gourmande/.htaccess
中有更多规则?如果是,则编辑问题并粘贴它。如果没有,那么您可以将该
/balade gourmande/.htaccess
重命名为其他名称。您不需要可选的
RewriteBase/
行,但使用它不会造成伤害。您也可以在此处包含任何
错误文档404
行。
DirectoryIndex index.php
ErrorDocument 404 /balade-gourmande/errorhandler.php
Options +FollowSymlinks -MultiViews
RewriteEngine On

# Add ending slash
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{THE_REQUEST} \s/+.*?[^/][\s?]
RewriteRule [^/]$ %{REQUEST_URI}/ [R=301,L]

RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{DOCUMENT_ROOT}/$1\.php -f [NC]
RewriteRule ^(.+?)/?$ /$1.php [L]