Forum Moderators: phranque

Message Too Old, No Replies

Quick mod rewrite question

         

ca3le

5:46 am on Sep 8, 2010 (gmt 0)

10+ Year Member



How would I use mod_rewrite to change

this...

[sitename.url...]

to this

[sitename.url...]

I just need to drop the "." and everything following it.

thanks in advance

ca3le

5:48 am on Sep 8, 2010 (gmt 0)

10+ Year Member



oops.. I should have put that in code tags

http://sitename.url/forum/topic/10325.4395-

to

http://sitename.url/forum/topic/10325-


I need the dash at the end too...

ca3le

6:35 am on Sep 8, 2010 (gmt 0)

10+ Year Member



Okay, I got it... I had it correct but I needed to put it in the .htaccess within the directory... other rules in there apparently were causing it not to work.

Here was my solution.

RewriteRule ^topic/([^/]+)\.([^/]+)\-$ /ipb/topic/$1- [R=301,L]
RewriteRule ^topic/([^/]+)\;([^/]+)-$ /ipb/topic/$1- [R=301,L]

g1smd

6:24 pm on Sep 8, 2010 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



You should also add the protocol and domain name to the redirect target.

Finally, link to the correct URL. Your code changes nothing, it merely tells browsers to request a different URL.

jdMorgan

9:22 pm on Sep 8, 2010 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Only one rule is needed, along with some corrections to the subpatterns and corrections as noted above:

RewriteRule ^topic/([0-9]+)[.;][0-9]+-$ http://www.example.com/ipb/topic/$1- [R=301,L]

Again, this is a redirect. It does not change the URL or change the filepath associated with the URL. It simply tells the browser to re-request what it wanted the first time, but using the new, shorter URL. If you actually want to change the URL, then you will have to edit your HTML pages or edit the script(s) that produce those HTML pages. It is HTML pages, not servers, that define URLs.

Be sure that before using this code, you correct all of the links on your site to use the new shorter format. The major search engines "don't like it" when they follow a link from your own site to your own site, and encounter a redirect... That indicates poor site management, and cannot be a help to your pages' rankings...

Jim