0

Let's say my domain is: www.site.name.jp
I want to remove www and the .html from the subpages as in: www.site.name/about.html

What should I do? I've been using the code bellow and, actually, it is working! But I'm a little afraid it's having a side effect on my Google crawl's analysis.

Options +MultiViews

RewriteCond %{HTTP_HOST} ^www\.web.roidesign\.jp [NC]
RewriteRule ^/(.*)       http://web.roidesign.jp/$1 [L,R=301]

<IfModule mod_deflate.c>
  #Force deflate for mangled headers
  <IfModule mod_setenvif.c>
    <IfModule mod_headers.c>
      SetEnvIfNoCase ^(Accept-EncodXng|X-cept-Encoding|X{15}|~{15}|-{15})$ ^((gzip|deflate)\s*,?\s*)+|[X~-]{4,13}$ HAVE_Accept-Encoding
      RequestHeader append Accept-Encoding "gzip,deflate" env=HAVE_Accept-Encoding
    </IfModule>
  </IfModule>

  #HTML, TXT, CSS, JavaScript, JSON, XML, HTC:
  <IfModule filter_module>
    FilterDeclare   COMPRESS
    FilterProvider  COMPRESS  DEFLATE resp=Content-Type $text/html
    FilterProvider  COMPRESS  DEFLATE resp=Content-Type $text/css
    FilterProvider  COMPRESS  DEFLATE resp=Content-Type $text/plain
    FilterProvider  COMPRESS  DEFLATE resp=Content-Type $text/xml
    FilterProvider  COMPRESS  DEFLATE resp=Content-Type $text/x-component
    FilterProvider  COMPRESS  DEFLATE resp=Content-Type $application/javascript
    FilterProvider  COMPRESS  DEFLATE resp=Content-Type $application/json
    FilterProvider  COMPRESS  DEFLATE resp=Content-Type $application/xml
    FilterProvider  COMPRESS  DEFLATE resp=Content-Type $application/xhtml+xml
    FilterProvider  COMPRESS  DEFLATE resp=Content-Type $application/rss+xml
    FilterProvider  COMPRESS  DEFLATE resp=Content-Type $application/atom+xml
    FilterProvider  COMPRESS  DEFLATE resp=Content-Type $application/vnd.ms-fontobject
    FilterProvider  COMPRESS  DEFLATE resp=Content-Type $image/svg+xml
    FilterProvider  COMPRESS  DEFLATE resp=Content-Type $application/x-font-ttf
    FilterProvider  COMPRESS  DEFLATE resp=Content-Type $font/opentype
    FilterChain     COMPRESS
    FilterProtocol  COMPRESS  DEFLATE change=yes;byteranges=no
  </IfModule>

  <IfModule !mod_filter.c>
    #Legacy versions of Apache
    AddOutputFilterByType DEFLATE text/html text/plain text/css application/json
    AddOutputFilterByType DEFLATE application/javascript
    AddOutputFilterByType DEFLATE text/xml application/xml text/x-component
    AddOutputFilterByType DEFLATE application/xhtml+xml application/rss+xml 
    AddOutputFilterByType DEFLATE application/atom+xml
    AddOutputFilterByType DEFLATE image/svg+xml application/vnd.ms-fontobject 
    AddOutputFilterByType DEFLATE application/x-font-ttf font/opentype
  </IfModule>
</IfModule>

1 Answers1

1

You can use this rule as your first rule to remove www and .html from URLs:

RewriteEngine On

RewriteCond %{HTTP_HOST} ^www\. [NC,OR]
RewriteCond %{THE_REQUEST} \.html[\s?] [NC]
RewriteCond %{HTTP_HOST} ^(?:www\.)?(.+)$ [NC]
RewriteRule ^(.+?)(?:\.html)?$ http://%1/$1 [R=301,L,NC,NE]

# now add .html internally
RewriteCond %{REQUEST_FILENAME}.html -f
RewriteRule ^(.+?)/?$ $1.html [L]
anubhava
  • 761,203
  • 64
  • 569
  • 643
  • It seemed to have worked, but actually I am getting this: site.name/about. (there is a dot in the end) – Felipe Felix de Luca Oct 05 '16 at 08:11
  • Ah sorry I had a. typo. Try my edited answer after clearing your browser cache. – anubhava Oct 05 '16 at 10:11
  • Thank you for correcting the code, @anubhava, but it is still not working :/ When I'm in my website's home page and I click on any link of my main menu, I am receiving something like "site.name/about", witch is correct, but the page doesn't display anything. I tried to input in my links(href) both formats: with and without .html. The result was the same - the page doesn't display. – Felipe Felix de Luca Oct 06 '16 at 07:40
  • Display thing might be due to relatives paths being used for `css/js/images`. Test in Chrome dev tool with caching disabled and check in Networking tab what are 404s you're getting. – anubhava Oct 06 '16 at 07:45
  • Would you like to check it there? I can't find the type of error I am getting here. The link is this one: http://web.roidesign.jp/ and the problem is when I am trying to access the other pages from the top menu. – Felipe Felix de Luca Oct 06 '16 at 07:53
  • Sorry, it is still not working :/ my links doesn't come with .html – Felipe Felix de Luca Oct 06 '16 at 09:00
  • No that's not correct anymore as `http://web.roidesign.jp/about` is working fine now. – anubhava Oct 06 '16 at 09:28
  • 1
    Can you show your full existing .htaccess in question so that I can give you an answer to adapt that. – anubhava Oct 06 '16 at 09:42