Forum Moderators: phranque
Using an extension like .html locks you into that file format.
@lucy24 No more than going extensionless. It's the same rewrite either way.
RewriteRule ^paintings/mice/([a-jw]\w+)\.html /paintings/critters/critterlinks.php?subdir=mice&page=$1 [L,NS]
RewriteRule ^fun/CheesyNovel/chap(\d+)\.html /fun/CheesyNovel/cnlinks.php?chapter=$1&page=CheesyNovel [L]
"If I can do it, anyone can." [webmasterworld.com...] .
4) Various types of redirect
The common SEO redirect is ensuring that a canonical domain is used, normally www vs. non-www. There are also a couple of other redirects you might find useful. I have kept them simple here, but often times you will want to combine these to ensure you avoid chaining redirects:
# Ensure www on all URLs.
RewriteCond %{HTTP_HOST} ^example.com [NC]
RewriteRule ^(.*)$ http://www.example.com/$1 [L,R=301]
# Ensure we are using HTTPS version of the site.
RewriteCond %{HTTPS} !on
RewriteRule (.*) [%{HTTP_HOST}%{REQUEST_URI}...] [L,R=301]
# Ensure all URLs have a trailing slash.
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_URI} !(.*)/$
RewriteRule ^(.*)$ http://www.example.com/$1/ [L,R=301]
[moz.com...]
what time is required to do this - minutes or hours?
RewriteCond %{HTTPS} !on [OR]
RewriteCond %{HTTP_HOST} !^(www\.example\.com)?$
RewriteRule (.*) https://www.example.com/$1 [R=301,L]
Note that the domain-name part is expressed as a negative: "If the hostname is anything other than the exact form I want or exactly nothing". The "exactly nothing" part (the parentheses and question mark) is a legacy from some older types of request that don't send a hostname at all. I, personally, have never seen a request without the "Host:" header; it's possible that the server adds one if it's absent (I'm on shared hosting). 301 a directory URL and all of its contents to another
If you have redesigned your site architecture and renamed a directory, you need to create a 301 for the entire directory. Here’s how:
RedirectMatch 301 ^/oldname/ [xyz.com...]
[internetmarketingninjas.com...] .
RedirectMatch