Forum Moderators: phranque
[edited by: bill at 4:10 am (utc) on Sep 15, 2017]
[edit reason] de-link code [/edit]
RewriteRule ^([^.]+\.htm)l https://www.example.com/$1 [R=301,L]
There are others; see above about literal . in an URL. RewriteCond %{HTTPS} !on [OR]
RewriteCond %{HTTP_HOST} !^(www\.example\.com)?$
RewriteRule (.+) https://www.example.com/$1 [R=301,L]
That's assuming you only have one hostname using this particular htaccess. If there are many, it gets more complicated. If they request ourdomain.acre, they get a 404 error. It is the last item that I was trying to correct.wtf? Please tell me something got garbled here. If someone requests example.org, they won't end up on example.com.
[edited by: not2easy at 10:45 pm (utc) on Sep 15, 2017]
[edit reason] unlinked/removed extra . (?) [/edit]
# change dot html to dot htm
RewriteRule ^([^.]+\.htm)l https://example.com/$1 [R=301,L] had an extra '.' after the // and before the example.com part of the Rewrite target URL. Hopefully that was a typo?
# change http:// to https://
RewriteCond %{HTTPS} !on [OR]
RewriteCond %{HTTP_HOST} !^(example\.com)?$
RewriteRule (.+) https://example.com/$1 [R=301,L]
The only periods are dot com and dot htm (css,js, svg,jpg, etc)
RewriteRule ^([^.]+)$ https://example.com/$1.htm [R=301,L]
RewriteRule !\.[a-z]{2,4}$ https://example.com%{REQUEST_URI}.htm [R=301,L]
If you use + (1 or more) instead of * (0 or more) then it will miss the document root when used in a .htaccess context. (?)Oh, right. I really should make a habit of copying-and-pasting from my own htaccess files--which by now should have it right--rather than just typ(o)ing from scratch every time.
^([^.]+[^./])$
BUT you will notice that this is also the pattern for legitimate (physical) directories minus the final / slash--a pattern that search engines can and do ask for. Normally mod_dir handles it--that's one of its two jobs--but you sure as ### don't want to bother with a -d test every time.
So they type into the address bar "example.com/units/acre", and they get a 404 error. We get a lot of these.Jack1014 - do you have a Site Search?
RewriteRule ^([^.]+)$ https://example.com/$1.htm [R=301,L]No, no, you can't do this--unless your site's URL structure is perfectly flat, with no directories whatsoever, which your example of “example.com/units/acre” indicates is not the case. Otherwise any request for
RewriteCond %{REQUEST_URI} !^(realdir|otherdir|thirddir|dir/subdir|dir/othersub)
RewriteRule ^([^.]+[^./])$ https://www.example.com/$1.htm [R=301,L]
but the exclusions in the RewriteCond should be set up to deal with requests that you actually get. And if the invalid requests are only for certain directories, the body of the rule should be constrained to something that looks like RewriteRule ^(onedir|otherdir)/([^.]+[^./])$ https://www.example.com/$1/$2.htm [R=301,L]
Matter of fact, the ([^.]+[^./])$ part may well be reducible to (\w+)$. Again, this depends on which URLs on your site actually exist. ... this is also the pattern for legitimate (physical) directories
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI} !^(realdir|otherdir|thirddir|dir/subdir|dir/othersub)
Actually, because of scraping, robots (Chinese robots, lately) request every conceivable permutation of the urllist, including directories, sub-directories, sub-sub-directories. So there is someone looking at directories.IMO pandering to bots is futile. Ignore the 404 errors caused by these UAs, they can be endless; unless there is a valid reason of course.
RewriteCond %{REQUEST_URI} !^/(onedir|otherdir)
RewriteRule ^(\w+/\w+)$ https://example.com/$1.htm [R=301,L]
If, on the other hand, the spurious type-ins are limited to just a few directories, a possible rule--conditionless--is RewriteRule ^((onedir|otherdir|thirddir)/\w+)$ https://example.com/$1.htm [R=301,L]
^((onedir|otherdir|thirddir)/\w+)(?:\.html)?$
(i.e. optional incorrect .html which is not captured) but this is probably not the most efficient way. ^(units/\w-)$
Gosh, that suddenly got a whole lot simpler didn't it :) RewriteCond %{REQUEST_URI} !^/units/(uimages|audio|about|symbol|cheating|charts|country|general)$
It is standard practice for search engines to make requests like sana_lamjel.htmlHa! So you actually do use lowlines. Those are covered by the \w locution.
<ifmodule mod_deflate.c>