Regex 404使用.htaccess重定向时,因为它';正在删除子目录
我想做的是通过删除.html来创建一个URL友好的站点。这是我的.htaccess:Regex 404使用.htaccess重定向时,因为它';正在删除子目录,regex,apache,.htaccess,mod-rewrite,redirect,Regex,Apache,.htaccess,Mod Rewrite,Redirect,我想做的是通过删除.html来创建一个URL友好的站点。这是我的.htaccess: RewriteCond %{THE_REQUEST} \s/+rscares/(.*?)\.html[\s?] [NC] RewriteRule ^ %1 [R=301,L,NE] #example.com/page will display the contents of example.com/page.html RewriteEngine On RewriteBase /rscares/ Rewri
RewriteCond %{THE_REQUEST} \s/+rscares/(.*?)\.html[\s?] [NC]
RewriteRule ^ %1 [R=301,L,NE]
#example.com/page will display the contents of example.com/page.html
RewriteEngine On
RewriteBase /rscares/
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}.html -f
RewriteRule ^(.+?)/?$ $1.html [L]
这就是问题所在,我正在一个子文件夹中进行测试,所以如果我键入example.com/folder/page
工作正常,但是如果我键入example.com/folder/page.html
它会重定向到example/page
,我会得到一个404,因为页面不存在。我想重定向到重定向之前的标签。有什么帮助吗?谢谢。您可以使用以下代码:
RewriteEngine On
RewriteBase /rscares/
RewriteCond %{THE_REQUEST} \s/+(rscares/.+?)\.html[\s?] [NC]
RewriteRule ^ /%1 [R=301,L,NE]
#example.com/page will display the contents of example.com/page.html
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}.html -f
RewriteRule ^(.+?)/?$ $1.html [L]
您是否在行上的
RewriteEngine之后使用了RewriteBase/folder/
?您能否显示您的/文件夹/.htaccess
?RewriteBase上的RewriteEngine/rscares/oh不在注释中,它不可读。编辑您的问题并发布完整的.htaccess
@anybhave。你好,anubhava,我更新了cod,这是我所有的.htaccess。在上重写引擎之前,您有我建议的301规则。看看我的答案应该是什么。