简体   繁体   中英

301 htaccess redirect dynamic url help needed

I'm trying to redirect this

hhttp://www.website.net/forum/index.php?showtopic=12345

to

hhttp://www.website.ORG/forum/t12345

12345 being the dynamic topic ID

I also need any information to be stripped away if it is found after the topic ID, for example

hhttp://www.website.net/forum/index.php?showtopic=12345&view=getlastpost

I want &view=getlastpost or any similar that may appear after the ID number to be get rid of.

I've tried

RewriteCond %{QUERY_STRING} ^(([^&] &) )showtopic=([^&]+)&?(.*)?$ RewriteRule ^index.php$ http://www.website.org/forum/t%3?%1%4/ [L,R=301]

but it didn't work. I get trash in the URL.

hhttp://www.website.org/forum/index.php?showtopic=29294&view=getlastpost (when that link is clicked - the result is hhttp://www.website.net/forum/t29294?view=getlastpost/)

hhttp://www.website.org/forum/index.php?showtopic=29029 (when that link is clicked - the result is hhttp://www.website.net/forum/t29029?/).

How can I clear it out?

$2 implies there are two bracketed areas, but I only see one in your rule, so changed that to $1.

Also your URL starts /forum/ so need to include that in the rule.

And the . in index.php needs to be escaped if you don't want it treated as a regex special character.

And if you want to ditch anything after the showtopic=1234 then just remove the $ that indicates the end of the string

RewriteRule ^forum/index\.php?showtopic=([0-9]*) http://www.website.org/forum/t$1/ [L,R=301]

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM