Linode Forum
Linode Community Forums
 FAQFAQ    SearchSearch    MembersMembers      Register Register 
 LoginLogin [ Anonymous ] 
Post new topic  Reply to topic
Author Message
PostPosted: Sat Jun 25, 2011 7:53 am 
Offline
Senior Newbie

Joined: Wed Jun 15, 2011 8:37 am
Posts: 13
Website: http://aplawrence.com
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.


Top
   
 Post subject:
PostPosted: Sat Jun 25, 2011 8:14 am 
Offline
Senior Member

Joined: Sun Mar 07, 2010 7:47 pm
Posts: 1970
Website: http://www.rwky.net
Location: Earth
What webserver?

_________________
Paid support
How to ask for help
1. Give details of your problem
2. Post any errors
3. Post relevant logs.
4. Don't hide details i.e. your domain, it just makes things harder
5. Be polite or you'll be eaten by a grue


Top
   
 Post subject:
PostPosted: Sat Jun 25, 2011 8:38 am 
Offline
Senior Newbie

Joined: Wed Jun 15, 2011 8:37 am
Posts: 13
Website: http://aplawrence.com
obs wrote:
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..


Top
   
 Post subject:
PostPosted: Sat Jun 25, 2011 9:16 am 
Offline
Senior Member

Joined: Sun Mar 07, 2010 7:47 pm
Posts: 1970
Website: http://www.rwky.net
Location: Earth
Try
Code:
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

_________________
Paid support
How to ask for help
1. Give details of your problem
2. Post any errors
3. Post relevant logs.
4. Don't hide details i.e. your domain, it just makes things harder
5. Be polite or you'll be eaten by a grue


Top
   
 Post subject:
PostPosted: Sat Jun 25, 2011 9:35 am 
Offline
Senior Newbie

Joined: Wed Jun 15, 2011 8:37 am
Posts: 13
Website: http://aplawrence.com
Never mind - caching - it is working and thanks!!

obs wrote:
Try
Code:
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!!


Top
   
 Post subject:
PostPosted: Sat Jun 25, 2011 9:49 am 
Offline
Senior Member

Joined: Sun Mar 07, 2010 7:47 pm
Posts: 1970
Website: http://www.rwky.net
Location: Earth
No problem :) for further reading you should learn about regular expressions, apache rewrite rules are basically regexs.

_________________
Paid support
How to ask for help
1. Give details of your problem
2. Post any errors
3. Post relevant logs.
4. Don't hide details i.e. your domain, it just makes things harder
5. Be polite or you'll be eaten by a grue


Top
   
 Post subject:
PostPosted: Sat Jun 25, 2011 9:52 am 
Offline
Senior Newbie

Joined: Wed Jun 15, 2011 8:37 am
Posts: 13
Website: http://aplawrence.com
obs wrote:
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..


Top
   
Display posts from previous:  Sort by  
Post new topic  Reply to topic


Who is online

Users browsing this forum: No registered users and 2 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
Jump to:  
RSS

Powered by phpBB® Forum Software © phpBB Group