Redirect from trailing junk
For example, I saw this recently:
The /Bofcusm/861.html is fine, but I can't seem to figure out how to redirect that without getting a loop.
What I'd really like is a general rewrite to get rid of "%ANYTHINg" because there seem to be a lot of people who carelessly cut and paste links and pick up %20.. though where this %2520 came from, I have no idea.
6 Replies
@obs:
What webserver?
Ooops - sorry. Apache2.
I know it's probably Rewrite and I really, really need to spend the time to understand that. Just one more thing I haven't gotten to yet..
I saw this while Googling
RewriteCond %{THE_REQUEST} \ (/.*?)(%20)+\ [NC]
RewriteRule . /$1 [R=301,L]
Bit that's only spaces.. I want ANY "%" sequence removed.
So I tried
RewriteCond %{THE_REQUEST} \ (/.html)(\%.)+\ [NC]
RewriteRule . /$1 [R=301,L]
Nope..
RewriteRule (.*).html.+ $1.html [R=301]
````
Translation is
(.*) match all characters and store them in $1
.html match only .html files
.+ match any characters at least 1 character in length
$1.html redirect to the (*.).html
[R=301] issue a 301 redirect so the user sees the .html page in the url instead of the .html%junk page
@obs:
Try````
RewriteRule (.*).html.+ $1.html [R=301]````
Translation is
(.*) match all characters and store them in $1
.html match only .html files
.+ match any characters at least 1 character in length
$1.html redirect to the (*.).html
[R=301] issue a 301 redirect so the user sees the .html page in the url instead of the .html%junk page
Ok, so here is my config now:
RewriteEngine On
RewriteCond %{HTTP_HOST} .
RewriteCond %{HTTP_HOST} !^aplawrence.com
RewriteRule (.*)
RewriteRule (.*).html.+ $1.html [R=301]
Not working - no condition?
Never mind - caching - it is working and thanks!!
@obs:
No problem
:) for further reading you should learn about regular expressions, apache rewrite rules are basically regexs.
I know regex, but do not yet understand the flow of the mod_rewrite. It is obviously worth learning..