在 .htaccess 上重定向添加 .html [英] Redirect adding .html on .htaccess
问题描述
我在 .htaccess 文件中使用这个正则表达式 o 重定向到相同的 url,并在末尾添加 .html
I'm using this regex o redirect in .htaccess file to the same url adding .html at the end
RedirectMatch 301 ^\/es(?:\/[\w-]+){3}$ $1.html
如果我不使用 $1
就没有错误,我不知道有什么问题
If I don't use $1
there is no error , I don't know what is wrong
我也试过这个:
RewriteEngine On
RewriteCond %{REQUEST_URI} ^\/es(?:\/[\w-]+){3}$
RewriteRule ^(.*)$ $1.html
但它什么都不做
推荐答案
根据您显示的尝试,要进行内部重写,请尝试遵循 .htaccess 规则文件中设置的规则.在测试您的 URL 之前,请确保清除浏览器缓存.请确保您的 htaccess 文件存在于根目录中.
With your shown attempts, to do internal rewrite please try following Rules set in your .htaccess Rules file. Please make sure to clear your browser cache before testing your URLs. Please make sure your htacces file is present in root.
RewriteEngine ON
RewriteCond %{DOCUMENT_ROOT}/$1.html -f [NC]
RewriteRule ^es(?:/[\w-]+){3}/?$ $1.html [NC,L]
第二种解决方案: 要么使用上述规则,要么一次只遵循以下规则.如果您想在浏览器上重定向,请尝试以下操作:
2nd solution: Either use above OR following rules only at a time. In case you want to redirect on browser then try following:
RewriteEngine ON
RewriteCond %{DOCUMENT_ROOT}/$1.html -f [NC]
RewriteRule ^es(?:/[\w-]+){3}/?$ $1.html [NC,L]
这篇关于在 .htaccess 上重定向添加 .html的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!