是否可以从weblity.pl/page重定向到weblity.pl/page/?我的.htaccess文件是我的htaccess文件。
您的.htaccess中有正确的行,但是您只需要将[l]标志更改为[l,r = 301]
RewriteCond %{REQUEST_FILENAME} !-f #checks if current URI leads to real file
RewriteCond %{REQUEST_URI} !(.*)/$ #checks if URI ends by slash, if not goes next
RewriteRule ^(.*)$ http://paweljanicki.pl/$1/ [L] #this line changes a URI
您需要更改为:
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_URI} !(.*)/$
RewriteRule ^(.*)$ http://paweljanicki.pl/$1/ [L,R=301] #or skip 301 code [L,R]
#R=302 by default, but you can set any valid HTTP response status code 300-399
关键是[l]标志不会输出重定向到浏览器,但是Apache将在带有End Slash的阴影中处理 weblot.pl/page uri(例如/page/)。
Apache Docs的更多信息重写标志
默认情况下,mod_dir通过 DirectorySlash
指令(默认情况下为on"为您执行此操作。这意味着,如果Apache认为您的请求是目录,并且缺少尾随的斜杠,MOD_DIR将301将请求重定向到尾斜线。
但是,对于CMS或其他内容中的虚拟目录,Apache不会意识到MOD_DIR需要处理后斜线。因此,您可以尝试将尾随的斜线附加到所有内容上,都不指向现有文件或目录,或者针对现有目录,然后 *关闭mod_dir *。
在您的文档root的HTACCESS文件中,添加以下规则(高于您可能已经拥有的任何类型的路由规则:
DirectorySlash Off
RewriteEngine On
# if request is for a directory
RewriteCond %{REQUEST_FILENAME} -d
# and is missing the trailing slash
RewriteRule ^(.*[^/])$ /$1/ [L,R=301]
# if request isn't for an existing directory or a file
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
# and no trailing slash
RewriteRule ^(.*[^/])$ /$1/ [L,R=301]