开发者

How to strip trailing URL characters in htaccess

I'm hoping someone can help with this one. I run a forum written in Perl, and the forum does something to URLs that is causing search engines to create duplicates.

I'm thinking that the best way of handling this is to sort it at the htaccess level.

As an example, the following 4 URLs all go to the same page, but search engines are seeing one entry with three duplicates:

http://www.domain.com/forum/YaBB.pl?num=1234567890
http://www.domain.com/forum/YaBB.pl?num=1234567890/2
http://www.domain.com/forum/YaBB.pl?num=1234567890/19
http://www.domain.com/forum/YaBB.pl?num=1234567890/22

I'm looking get htaccess to redirect anything that has a forward-slash somewhere in the last three characters, to a URL that has the slash and trailing numbers removed. Using the above example:

Redirect 301 /forum/YaBB.pl?num=1234567890/2 to /forum/YaBB.pl?num=1234567890

Alternatively, to re-write URLs from that subdomain to strip "/n" and "/nn"

Anyone h开发者_运维百科ave any ideas?


Try this:

RewriteEngine On
RewriteBase /
RewriteRule ^cgi-bin/forum/YaBB\.pl\?num=([0-9]+)/[0-9]+$ cgi-bin/forum/YaBB.pl?num=$1 [R=302,L]

This should work, but let me know if it doesn't :) Also if it works, change the 'R=302' to 'R=301'


Try this rule:

Options +FollowSymLinks +SymLinksIfOwnerMatch

RewriteEngine On
RewriteBase /

RewriteCond %{QUERY_STRING} ^num=(\d+)/
RewriteRule ^(cgi-bin/forum/YaBB\.pl)$ /$1?num=%1 [R=301,L] 

Tested on local Apache installation -- works fine for me.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜