Redirect from trailing junk

Every now and then somebody makes a link to one of my pages and they fat finger it.

For example, I saw this recently:

http://aplawrence.com/Bofcusm/861.html%2520

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..

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

Never mind - caching - it is working and thanks!!

@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 (.*) http://aplawrence.com/$1 [R=301,L]

RewriteRule (.*).html.+ $1.html [R=301]

Not working - no condition?

Never mind - caching - it is working and thanks!!

No problem :) for further reading you should learn about regular expressions, apache rewrite rules are basically regexs.

@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..

Reply

Please enter an answer
Tips:

You can mention users to notify them: @username

You can use Markdown to format your question. For more examples see the Markdown Cheatsheet.

> I’m a blockquote.

I’m a blockquote.

[I'm a link] (https://www.google.com)

I'm a link

**I am bold** I am bold

*I am italicized* I am italicized

Community Code of Conduct