我是htacces的新手。
我想创建类似stackoverflow的htaccess。
检查stackoverflow的所有URL,例如“通过htaccess在url中隐藏文件扩展名”。如果您放置.html / .php / .asp / .abc / .xyz任何东西,它只会重定向到“通过htaccess隐藏url中的文件扩展名”,即使您放置/最后也不起作用。
意思是我想说url filename包含任何键盘字符,它将在外部重定向。
以下是我目前的htaccess
RewriteEngine on
# To internally
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}\.html -f
RewriteRule ^(.*)$ $1.html
# To externally redirect /dir/file.html to /dir/file
RewriteCond %{THE_REQUEST} ^[A-Z]{3,}\s/+(.+?)\.html[\s?] [NC]
RewriteRule ^ %1 [R=301,L,NE]
您需要使用适当的``RewriteBase`:
RewriteEngine on
RewriteBase /folder1/folder2/
# To externally redirect /dir/file.html to /dir/file
RewriteCond %{THE_REQUEST} ^GET\s(.+?)\.html[\s?] [NC]
RewriteRule ^ %1 [R=301,L,NE]
# To internally
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}\.html -f
RewriteRule ^(.+?)/?$ $1.html [L]
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句