Solved

URL Rewrite

Posted on 2007-11-28
10
397 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
Visualize your virtual and backup environments

Create well-organized and polished visualizations of your virtual and backup environments when planning VMware vSphere, Microsoft Hyper-V or Veeam deployments. It helps you to gain better visibility and valuable business insights.

 

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
 

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

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In Solr 4.0 it is possible to atomically (or partially) update individual fields in a document. This article will show the operations possible for atomic updating as well as setting up your Solr instance to be able to perform the actions. One major …
Nothing in an HTTP request can be trusted, including HTTP headers and form data.  A form token is a tool that can be used to guard against request forgeries (CSRF).  This article shows an improved approach to form tokens, making it more difficult to…
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.
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.

685 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