开发者

Redirecting links without a .html extension to link with .html extension

开发者 https://www.devze.com 2023-02-17 12:58 出处:网络
After changing my site structure I need help redirecting links. How can I redirect all links that don\'t have a .html extension to the same link but with .html extension? The only link I don\'t want r

After changing my site structure I need help redirecting links. How can I redirect all links that don't have a .html extension to the same link but with .html extension? The only link I don't want redirected is /admin.

Example: google.com/hey -> google.com/hey.html
         google.com/hey.html -> do noth开发者_开发知识库ing 
         google.com/admin -> do nothing

Thanks in advance


Ohh sorry, try this man. The error was in the rewritecond.

RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !\.html$
RewriteRule (.+) $1.html  [L]


If these links are onpage links an non external ones a .htaccess solution could help. First be aware to use htaccess only if you do not have access to the server config, because htaccess slows the server down. Everything configured there can be configured as well in the .httpdconf

Sorry, I have not tested the code posted bellow but tell me if it has worked. http://httpd.apache.org/docs/2.0/mod/mod_rewrite.html

RewriteEngine On
RewriteCond %{REQUEST_FILENAME} > \.html
RewriteRule (.+) $1.html  [L]
0

精彩评论

暂无评论...
验证码 换一张
取 消