Problems, need help? Have a tip or advice? Post it here.
3 posts Page 1 of 1
I am trying to make root pages redirects to .html

I am dealing with a client who had on previous site all pages .htm, all SEO and google is indexed with those pages. Now i have a problem since pretty URL supports only .html, i have to make redirect from .htm (whoever finds pages on google) to redirect him on working .html.

I have managed to make it happen for all clonable pages to work and redirect from .htm to .html, but i cannot make it happen for root pages.

In root i have index.php and 5 pages .html

Right now, when i type example www.mysite.com/contact.htm it says page not found, even if i made an contact.htm file. Same goes for other pages in root, except index.php which redirects back /root

here is htaccess
Code: Select all
Options +SymLinksIfOwnerMatch -MultiViews
<IfModule mod_rewrite.c>
RewriteEngine On

#If your website is installed in a subfolder, change the line below to reflect the path to the subfolder.
#e.g. for http://www.example.com/subdomain1/subdomain2/ make it RewriteBase /subdomain1/subdomain2
RewriteBase /

#If you wish to use a custom 404 page, place a file named 404.php in your website's root and uncomment the line below.
#If your website is installed in a subfolder, change the line below to reflect the path to the subfolder.
#e.g. for http://www.example.com/subdomain1/subdomain2/ make it ErrorDocument 404 /subdomain1/subdomain2/404.php
#ErrorDocument 404 /404.php

#If your site begins with 'www', uncomment the following two lines
#RewriteCond %{HTTP_HOST} !^www\.
#RewriteRule ^(.*)$ http://www.%{HTTP_HOST}/$1 [R=301,L]


#DO NOT EDIT BELOW THIS


RewriteEngine on
RewriteBase /
RewriteRule ^(.*)\.htm$ $1.html [R=permanent]

RewriteRule ^index.php$ "" [R=301,L,QSA]

RewriteCond %{REQUEST_FILENAME} -d [OR]
RewriteCond %{REQUEST_FILENAME} -f
RewriteRule . - [L]

#slots.php
RewriteRule ^slots$ "$0/" [R=301,L,QSA]
RewriteRule ^slots/$ slots.php [L,QSA]
RewriteRule ^slots/.*?([^\.\/]*)\.html$ slots.php?pname=$1 [L,QSA]
RewriteRule ^slots/([1-2]\d{3})/(?:(0[1-9]|1[0-2])/(?:(0[1-9]|1[0-9]|2[0-9]|3[0-1])/)?)?$ slots.php?d=$1$2$3 [L,QSA]
RewriteRule ^slots/[^\.]*?([^/\.]*)/$ slots.php?fname=$1 [L,QSA]
RewriteRule ^slots/[^\.]*?([^/\.]*)$ "$0/" [R=301,L,QSA]

#root.php
RewriteRule ^root$ "$0/" [R=301,L,QSA]
RewriteRule ^root/$ root.php [L,QSA]
RewriteRule ^root/.*?([^\.\/]*)\.html$ root.php?pname=$1 [L,QSA]
RewriteRule ^root/([1-2]\d{3})/(?:(0[1-9]|1[0-2])/(?:(0[1-9]|1[0-9]|2[0-9]|3[0-1])/)?)?$ root.php?d=$1$2$3 [L,QSA]
RewriteRule ^root/[^\.]*?([^/\.]*)/$ root.php?fname=$1 [L,QSA]
RewriteRule ^root/[^\.]*?([^/\.]*)$ "$0/" [R=301,L,QSA]

#news.php
RewriteRule ^news$ "$0/" [R=301,L,QSA]
RewriteRule ^news/$ news.php [L,QSA]
RewriteRule ^news/.*?([^\.\/]*)\.html$ news.php?pname=$1 [L,QSA]
RewriteRule ^news/([1-2]\d{3})/(?:(0[1-9]|1[0-2])/(?:(0[1-9]|1[0-9]|2[0-9]|3[0-1])/)?)?$ news.php?d=$1$2$3 [L,QSA]
RewriteRule ^news/[^\.]*?([^/\.]*)/$ news.php?fname=$1 [L,QSA]
RewriteRule ^news/[^\.]*?([^/\.]*)$ "$0/" [R=301,L,QSA]

#globals.php
RewriteRule ^globals$ "$0/" [R=301,L,QSA]
RewriteRule ^globals/$ globals.php [L,QSA]
RewriteRule ^globals/.*?([^\.\/]*)\.html$ globals.php?pname=$1 [L,QSA]
RewriteRule ^globals/([1-2]\d{3})/(?:(0[1-9]|1[0-2])/(?:(0[1-9]|1[0-9]|2[0-9]|3[0-1])/)?)?$ globals.php?d=$1$2$3 [L,QSA]
RewriteRule ^globals/[^\.]*?([^/\.]*)/$ globals.php?fname=$1 [L,QSA]
RewriteRule ^globals/[^\.]*?([^/\.]*)$ "$0/" [R=301,L,QSA]

#freeplaygame.php
RewriteRule ^freeplaygame$ "$0/" [R=301,L,QSA]
RewriteRule ^freeplaygame/$ freeplaygame.php [L,QSA]
RewriteRule ^freeplaygame/.*?([^\.\/]*)\.html$ freeplaygame.php?pname=$1 [L,QSA]
RewriteRule ^freeplaygame/([1-2]\d{3})/(?:(0[1-9]|1[0-2])/(?:(0[1-9]|1[0-9]|2[0-9]|3[0-1])/)?)?$ freeplaygame.php?d=$1$2$3 [L,QSA]
RewriteRule ^freeplaygame/[^\.]*?([^/\.]*)/$ freeplaygame.php?fname=$1 [L,QSA]
RewriteRule ^freeplaygame/[^\.]*?([^/\.]*)$ "$0/" [R=301,L,QSA]

#download.php
RewriteRule ^download$ "$0/" [R=301,L,QSA]
RewriteRule ^download/$ download.php [L,QSA]
RewriteRule ^download/.*?([^\.\/]*)\.html$ download.php?pname=$1 [L,QSA]
RewriteRule ^download/([1-2]\d{3})/(?:(0[1-9]|1[0-2])/(?:(0[1-9]|1[0-9]|2[0-9]|3[0-1])/)?)?$ download.php?d=$1$2$3 [L,QSA]
RewriteRule ^download/[^\.]*?([^/\.]*)/$ download.php?fname=$1 [L,QSA]
RewriteRule ^download/[^\.]*?([^/\.]*)$ "$0/" [R=301,L,QSA]

#casino.php
RewriteRule ^casino$ "$0/" [R=301,L,QSA]
RewriteRule ^casino/$ casino.php [L,QSA]
RewriteRule ^casino/.*?([^\.\/]*)\.html$ casino.php?pname=$1 [L,QSA]
RewriteRule ^casino/([1-2]\d{3})/(?:(0[1-9]|1[0-2])/(?:(0[1-9]|1[0-9]|2[0-9]|3[0-1])/)?)?$ casino.php?d=$1$2$3 [L,QSA]
RewriteRule ^casino/[^\.]*?([^/\.]*)/$ casino.php?fname=$1 [L,QSA]
RewriteRule ^casino/[^\.]*?([^/\.]*)$ "$0/" [R=301,L,QSA]

#articles.php
RewriteRule ^articles$ "$0/" [R=301,L,QSA]
RewriteRule ^articles/$ articles.php [L,QSA]
RewriteRule ^articles/.*?([^\.\/]*)\.html$ articles.php?pname=$1 [L,QSA]
RewriteRule ^articles/([1-2]\d{3})/(?:(0[1-9]|1[0-2])/(?:(0[1-9]|1[0-9]|2[0-9]|3[0-1])/)?)?$ articles.php?d=$1$2$3 [L,QSA]
RewriteRule ^articles/[^\.]*?([^/\.]*)/$ articles.php?fname=$1 [L,QSA]
RewriteRule ^articles/[^\.]*?([^/\.]*)$ "$0/" [R=301,L,QSA]

#index.php
RewriteRule ^.*?([^\.\/]*)\.html$ ?pname=$1 [L,QSA]
RewriteRule ^([1-2]\d{3})/(?:(0[1-9]|1[0-2])/(?:(0[1-9]|1[0-9]|2[0-9]|3[0-1])/)?)?$ ?d=$1$2$3 [L,QSA]
RewriteRule ^[^\.]*?([^/\.]*)/$ ?fname=$1 [L,QSA]
RewriteRule ^\w[^\.]*?([^/\.]*)$ "$0/" [R=301,L,QSA]
</IfModule>


I hope you understand me.
Please don't change the rules generated by Couch for the .htaccess file.
Instead just add your custom redirect code (for the the older URLs) at the place indicated below -
Code: Select all
#If your site begins with 'www', uncomment the following two lines
RewriteCond %{HTTP_HOST} !^www\.
RewriteRule ^(.*)$ https://www.%{HTTP_HOST}/$1 [R=301,L]

#place all your custom redirects here
..

#DO NOT EDIT BELOW THIS

Hope it helps.
I did what you said and still doesn't help for root html files to work.

I am having few pages as not part of cms next to the php templates which are working properly with redirecting from .htm to .html
Why i did this is because i didn't manage to make pretty url work on root template pages as /example.html, so i did make standard html pages

Here is a list hierarchy
site-link.com/contact.html
/example.html
/example2.html
/example3.html
/slots.php (clonable)
/casino.php (clonable)
/index.php (non-clonable)
/download.php (clonable)
/freeplaygame.php (clonable)
/articles.php (clonable)

I want to achive making all link attempts from user to any .htm (wich doesnt exist mysite.com/example.htm) to be redirect to.html
For now, it is working for all clonable templates mysite.com/download/index.htm
3 posts Page 1 of 1