Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

How do I properly use Mod-Rewrite to change URL?

Posted on 2009-07-14
4
Medium Priority
?
276 Views
Last Modified: 2013-12-09
I am on a windows server with IIS.  Currently it is windows 2003 with IIS 6, but I will soon upgrade to 2007 and IIS 7.  However, I am using the third party IIS Mod-Rewrite from Micronovae, so I think the code should apply the same as running Apache.

I am currently testing code, and have found that I am getting the desired effect, however, I get the feeling I may be grossly misusing the rewrite rules, as I have not seen it done like this in the forum.  The goal is to have a URL like: http://www.something.com/subTopic/116/HeartHealth replace a URL like:  http://www.something.com/index.cfm/fuseaction/center.subTopicID/116/HeartHealth while displaying the first URL in the browser.  Also, I need to make sure that all the old URLs still work, but redirect to the new, cleaner URL.  

The code below redirects the URL to the new convention with a redirect, and then points back to the original without a redirect, so that the new URL is displayed in the browser.  It works to type in either convention. I will point all internal links  to the new URLs, but my concerns are:

1.  Will search engines penalize me for having duplicate content.  I.e. you can get the same content via two URLs OR will they not follow the old links anymore, because of the redirect(do I need to add a 301 somehow?)

2. The regex rule seems to be working, but I'm not sure if my wildcards and end of expression syntax may produce unexpected results.

3. Is there a better way to do this?

I would appreciate any help you can give me.  Thanks.

RewriteEngine On
 
RewriteRule ^/index.cfm/fuseaction/center.subTopic/subTopicID/(.*)$ /subtopic/$1 [R]
RewriteRule ^/subtopic/(.*)$ /index.cfm/fuseaction/center.subTopic/subTopicID/$1

Open in new window

0
Comment
Question by:dojoHobo
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
  • 2
4 Comments
 

Author Comment

by:dojoHobo
ID: 24854156
Increasing the point value; I know the information in the answer will be helpful to a lot of people.
0
 
LVL 18

Accepted Solution

by:
Hube02 earned 2000 total points
ID: 24855319
>>>> 1.  Will search engines penalize me for having duplicate content.  I.e. you can get the same content via two URLs OR will they not follow the old links anymore, because of the redirect(do I need to add a 301 somehow?) <<<<

I do not believe you have an issue with duplicate content here.
If the user requests: http://www.something.com/index.cfm/fuseaction/center.subTopicID/116/HeartHealth
they are redirected to: http://www.something.com/subTopic/116/HeartHealth

I would add a 301 to this if the rewrite engine you are using allows it, I would also add the "last rule" flag. On Apache this would be:

[R=301,L]

You may also need to provide the full url in the rewrite, so the whole thing would be:

 RewriteRule ^/index.cfm/fuseaction/center.subTopic/subTopicID/(.*)$ http://www.something.com/subTopic/$1 [R]


Then when the browser gets redirected to http://www.something.com/subTopic/116/HeartHealth
the page at: If the user requests: http://www.something.com/index.cfm/fuseaction/center.subTopicID/116/HeartHealth is loaded. But since this is a normal rewrite so the URL does not actually change. For search engine purposes this is the only URL

2. The regex rule seems to be working, but I'm not sure if my wildcards and end of expression syntax may produce unexpected results.

Your syntax looks perfectly valid. However, I notice the you start with a beginning / and this is different than on Apache, so there may be other differences in the engine as well

3. Is there a better way to do this?

To be honest, this looks perfectly valid and I can't think of a better way to do it, as long as you make sure you change all the current links in all the pages to the new, shorter URL. Then the only thing that will be redirected is when a link comes from an outside source. Once the search engines re-index your site it will have the new URLS due to the 301's
0
 

Author Closing Comment

by:dojoHobo
ID: 31603354
This is awesome information.  I think the redirect and last rule syntax is the same in this engine, so I will definitely add that.  

One last little bit, when I add the full (new) URL, as you showed, it doesn't replace just the ^index.cfm... part; it replaces the full old URL with the full new URL?  Is this the more standard way to do it?
0
 
LVL 18

Expert Comment

by:Hube02
ID: 24857898
The reason I said to add the full new url is that on Apache and Mod_Rewrite, if you use a 301 and do not include the full url, including the http://www.someserver.com/ Apache generates a system error, or at least that has been my experience so I always include it. This could be different on the rewrite module you are using. I have never actually used that one. The one we generally go with is ISAPPI. However, I had never heard of it before and plan to test it out. ISAPI has some significant differences from MOD_REWRITE and if this one is closer to the Apache standard then it may be a better choice. Less need to make changes when porting from Apache to IIS.

And you only need the full url in the second par, as the below that sends all requests to a new server

RewriteRule ^(.*)$ http://new.server.com/$1 [R=301,L]
0

Featured Post

Manage your data center from practically anywhere

The KN8164V features HD resolution of 1920 x 1200, FIPS 140-2 with level 1 security standards and virtual media transmissions at twice the speed. Built for reliability, the KN series provides local console and remote over IP access, ensuring 24/7 availability to all servers.

Question has a verified solution.

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

There’s a good reason for why it’s called a homepage – it closely resembles that of a physical house and the only real difference is that it’s online. Your website’s homepage is where people come to visit you. It’s the family room of your website wh…
When the s#!t hits the fan, you don’t have time to look up who’s on call, draft emails, call collaborators, or send text messages. An instant chat window is definitely the way to go, especially one like HipChat. HipChat is a true business app. An…
The viewer will get a basic understanding of what section 508 compliance can entail, learn about skip navigation links, alt text, transcripts, and font size controls.
Learn how to create flexible layouts using relative units in CSS.  New relative units added in CSS3 include vw(viewports width), vh(viewports height), vmin(minimum of viewports height and width), and vmax (maximum of viewports height and width).
Suggested Courses

670 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