Solved

URL Rewrite

Posted on 2007-11-28
10
380 Views
Last Modified: 2010-05-18
Hi, This is what I am looking to do since I changed from a forum with asp to php.

rewrite the old URL variables to the new ones that my current forum uses.

ie. old incoming url: http://my_domain/forum.asp?FORUM=2

or

ie old url http://my_domain/forum.asp?TOPIC_ID=32324

Take those turn them into this:

http://my_domain/forums/index.php?showforum=2

http://my_domain/forums/index.php?showtopic=32324

Appreciate the help. I'm a total n00b with this stuff:)
0
Comment
Question by:vfetty
  • 5
  • 4
10 Comments
 
LVL 2

Expert Comment

by:accrain
ID: 20370787
Rename the class in the code; FORUM to "showforum" and TOPIC_ID to "showtopic".
0
 
LVL 10

Expert Comment

by:wildzero
ID: 20371139
RewriteEngine on
RewriteBase /
RewriteRule ^forum.asp?FORUM=([0-9]+)$ /index.php?showforum=$1 [QSA,L]
RewriteRule ^forum.asp?TOPIC_ID=([0-9]+)$ /index.php?showtpic=$1 [QSA,L]

or, and probly the better way is to change QSA to R=301 like

RewriteEngine on
RewriteBase /
RewriteRule ^forum.asp?FORUM=([0-9]+)$ /index.php?showforum=$1 [R=301,L]
RewriteRule ^forum.asp?TOPIC_ID=([0-9]+)$ /index.php?showtpic=$1 [R=301,L]

and just stick that in an htaccess file in your document root.
If that dosn't work, change
([0-9]+)
to
(.+)
0
 
LVL 10

Expert Comment

by:wildzero
ID: 20371144
/index.php?showtpic=$1
should be
/index.php?showtopic=$1
0
 

Author Comment

by:vfetty
ID: 20371419
this one note working

RewriteEngine on
RewriteBase /forum/
RewriteRule ^forum.asp?FORUM=([0-9]+)$ /index.php?showforum=$1 [R=301,L]
RewriteRule ^topic.asp?TOPIC_ID=([0-9]+)$ /index.php?showtopic=$1 [R=301,L]
0
 

Author Comment

by:vfetty
ID: 20371433
sorry was in a rush last time, thanks for the replies here is what it says in the 404

Not Found

The requested URL /forum/topic.asp was not found on this server.
0
Get up to 2TB FREE CLOUD per backup license!

An exclusive Black Friday offer just for Expert Exchange audience! Buy any of our top-rated backup solutions & get up to 2TB free cloud per system! Perform local & cloud backup in the same step, and restore instantly—anytime, anywhere. Grab this deal now before it disappears!

 

Author Comment

by:vfetty
ID: 20372039
I looked over my response again and noticed I changed the RewriteBase to /forum/ since that is where my forum is located.  The issue is still happing when google comes from a search it 404's?  Please really need help!
0
 
LVL 10

Expert Comment

by:wildzero
ID: 20377355
Right first thing to look at is if apache is reading the .htaccess
Edit the .htaccess and just write junk in there, like
RewriteRule asdf^forum.asp?FORUM=([0-9asdf]+)$ /index.php?showforum=$1 [R=301,L]asdf

this should throw a 500 internal server error

If it does then we are on the right course, this .htaccess is in the document root folder? Do you have another .htaccess which is in your /forum/ folder?

And just to check, your folder structure was
/forum/topic.asp
and is now
/forum/topic.php?

if so I would suggest changing the htaccess to
RewriteEngine on
RewriteBase /
RewriteRule ^forum/forum.asp?FORUM=([0-9]+)$ /forum/index.php?showforum=$1 [R=301,L]
RewriteRule ^forum/topic.asp?TOPIC_ID=([0-9]+)$ /forum/index.php?showtopic=$1 [R=301,L]

the missing of the/ before forum at the station is intentional
0
 

Author Comment

by:vfetty
ID: 20377398
below is what I have been using that worked but I have another scenerio I do not know how to do:

/forum/topic.asp?TOPIC_ID=134385&whichpage=4

the whichpage=4 - how do I pick up that one.

<IfModule mod_rewrite.c>
   Options +FollowSymLinks
   Options +Indexes
   RewriteEngine On
   RewriteBase /
   RewriteCond %{QUERY_STRING} TOPIC_ID=([0-9]+)
   RewriteCond %{QUERY_STRING} FORUM=([0-9]+)
   RewriteRule ^topic.asp$ /forum/index.php?showtopic=%1 [R=301,L,QSA]
   RewriteRule ^forum.asp$ /forum/index.php [R=301,L,QSA]
</IfModule>
0
 
LVL 10

Accepted Solution

by:
wildzero earned 500 total points
ID: 20377507
with the new php site, what is the equlviant of TOPIC_ID=134385&whichpage=4 ?
index.php?showtopic=134385&page4?

RewriteRule ^forum/topic.asp?TOPIC_ID=([0-9]+)&whichpage=([0-9+)$ /forum/index.php?showtopic=$1&page=$2 [R=301,L]
0
 

Author Comment

by:vfetty
ID: 20377923
actually after thinking about it I just need anytime TOPIC_ID=134385&whichpage=4 is present just to go to forum/index.php  . How would I do that?
0

Featured Post

Find Ransomware Secrets With All-Source Analysis

Ransomware has become a major concern for organizations; its prevalence has grown due to past successes achieved by threat actors. While each ransomware variant is different, we’ve seen some common tactics and trends used among the authors of the malware.

Join & Write a Comment

Developers of all skill levels should learn to use current best practices when developing websites. However many developers, new and old, fall into the trap of using deprecated features because this is what so many tutorials and books tell them to u…
Password hashing is better than message digests or encryption, and you should be using it instead of message digests or encryption.  Find out why and how in this article, which supplements the original article on PHP Client Registration, Login, Logo…
The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…
This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.

758 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

23 Experts available now in Live!

Get 1:1 Help Now