Forum Moderators: phranque

Message Too Old, No Replies

URL Rewrites

Poor man's duct tape or legitimate fix?

         

CWebguy

2:04 pm on Sep 4, 2007 (gmt 0)

10+ Year Member



On the topic of mod rewrites (changing the name and location of URL's), is this good practice or a cheap fix?

I have a content managment system that gives too many directories and poor URL's and I am looking into learning some mod rewrites to fix this. Is there a downside to this? Does this cause unneccessary server load, or is it an efficient respectable way to fix this?

For me right now, this seems like it will be the easiest thing to use to change the URL structure to something more pleasant. Is this a good fix or do you recommend something else?

Thanks.

[edited by: CWebguy at 2:05 pm (utc) on Sep. 4, 2007]

g1smd

2:30 pm on Sep 4, 2007 (gmt 0)

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



See the answer I just wrote in: [webmasterworld.com...]

CWebguy

2:36 pm on Sep 4, 2007 (gmt 0)

10+ Year Member



g1, thanks for the reply. But, I think you might have confused a redirect with a rewrite (or maybe not, I was a little confused reading your post just because a lot of this is new to me).

What I am looking to do is different than a redirect (which is simply old URL to new updated URL). Because the pages I am using do not physically exist on the server (they are dynamically created) I don't think there is a need to have a physical page that I am linking to, just to change the URL that "goes/points to" to a certain file/page that the user has requested. Does this make sense or am I off track? (I am guessing that rewrites are different than redirects, correct?)

So in a sense you can rewrite an URL that looks like this

[mydomain.com...]

into something like

[mydomain.com...] (or whatever you like)

I guess my question is, is this acceptable to do using a mod rewrite in terms of effecieny, etc., or is there a better more reliable way?

[edited by: CWebguy at 2:40 pm (utc) on Sep. 4, 2007]

g1smd

2:51 pm on Sep 4, 2007 (gmt 0)

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



Terminology.

A rewrite takes the URL request from the browser and changes it into a server filepath to get the content from.

A redirect takes a request for one URL and sends a reply that forces the browser make a new request for a different URL.

.

Which of those two URLs do you want the user to see in their browser?

[edited by: g1smd at 3:03 pm (utc) on Sep. 4, 2007]

nowpc

2:52 pm on Sep 4, 2007 (gmt 0)

10+ Year Member



Take another look at the linked reply from g1smd. It's all you need.

g1smd

2:58 pm on Sep 4, 2007 (gmt 0)

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



If the file on the server that produces the content is located at /myscript.php?parameter=value and you want the user to see a tidy URL like: http://www.domain.com/something/value then you need:

- a rewrite from http://(www.)domain.com/something/(value) URL to the server filepath /myscript.php?parameter=(value) to fetch the content from the real (and hidden) location.

- and you need a redirect from URL http://(www.)domain.com/myscript.php?parameter=(value) to new URL http://(www.)domain.com/something/(value) with [R=301] to prevent the content being accessed at the parameter-based URL.

The links on your pages will need to be in this format: http://www.domain.com/something/value.

[edited by: g1smd at 3:16 pm (utc) on Sep. 4, 2007]

CWebguy

3:07 pm on Sep 4, 2007 (gmt 0)

10+ Year Member



I'm a little confused. You are saying that I need a redirect and a rewrite?

Thanks.

g1smd

3:13 pm on Sep 4, 2007 (gmt 0)

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



Yes. Otherwise your content will be accessible at two URLs for each page and that Duplicate Content problem will affect your rankings.

[edited by: g1smd at 3:13 pm (utc) on Sep. 4, 2007]

CWebguy

3:13 pm on Sep 4, 2007 (gmt 0)

10+ Year Member



The CMS software I am using has a "hack" written to output clean URL's but requires the changing of a certain file on the server which a) I don't know where it is on the server and b) if I did know, I doubt I would want to mess with, so I feel more comfortable doing a mod_rewrite as this seems to be this answer to what I am needing. Thanks so far!

CWebguy

3:14 pm on Sep 4, 2007 (gmt 0)

10+ Year Member



Yes. Otherwise your content will be accessible at two URLs for each page and that Duplicate Content problem will affect your rankings.

Ok, I understand

g1smd

3:42 pm on Sep 4, 2007 (gmt 0)

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



>> a "hack" written to output clean URLs <<

The clean URLs should appear in the clickable links in the text of your content pages.

The mechanism to rewrite requests for clean URLs into parameter-based filenames to be fetched from the server, resides in some ModRewrite code located in the .htaccess file I expect.

CWebguy

3:45 pm on Sep 4, 2007 (gmt 0)

10+ Year Member



Yep, it also said I needed to change some kind of server file, something .php I had never heard of before. (Of course this hack was written about two years ago). Maybe I'll do some more searching.

Currently reading: [yourhtmlsource.com...] (seems to be what I need)

g1smd

3:49 pm on Sep 4, 2007 (gmt 0)

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



There are a few things that tutorial misses out.

Do not use [R]. That is a 302 redirect.

Use [R=301] to force a 301 redirect.

For the rewrite, no [R] is needed at all.

CWebguy

4:09 pm on Sep 4, 2007 (gmt 0)

10+ Year Member



cool, Thanks!

CWebguy

4:15 pm on Sep 4, 2007 (gmt 0)

10+ Year Member



I guess the thing I was wondering is, is a mod rewrite going to be hard on the server at high volumes or will it be ok? (is the levee going to break?)

g1smd

4:28 pm on Sep 4, 2007 (gmt 0)

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



If the rewrite code is efficient, negligible impact.

CWebguy

4:28 pm on Sep 4, 2007 (gmt 0)

10+ Year Member



The program I am using is Xoops (cool name huh?)

The hack comes with two files and these instructions:

How to install it?
------------------
Installation is simple:

1) Upload this two files to your Xoops root dir:
- loadpages.php
- xoops_shorturls.php
2) Modify your .htaccess file, the one you have in your Xoops root dir (if any)
and add the contents of the included .htaccess file. If you don't have one, just upload the one I provided.

3) In the Xoops root dir, there is a file named mainfile.php
Open it and add the following line just after the disclaimer (line 27 for
Xoops 2.06):

include "xoops_shorturls.php";

Save mainfile.php and upload it to your server.

IMPORTANT! IMPORTANT! IMPORTANT! IMPORTANT! IMPORTANT!
You have to edit the mainfile.php that is in your server, not the one that
originally comes with you Xoops, as this file is changed after installation.

After this, open your site. You should have ShortUrls working. Enjoy!

I am guessing that since this was written two years or so ago, maybe this guy never heard of mod rewrites, as the mod rewrites seem like they will accomplish the exact same thing, but maybe in a newer more effecient way (effecient is good!). What do you think?

CWebguy

4:29 pm on Sep 4, 2007 (gmt 0)

10+ Year Member



If the rewrite code is efficient, negligible impact.
Cool.

[edited by: CWebguy at 4:29 pm (utc) on Sep. 4, 2007]

CWebguy

4:33 pm on Sep 4, 2007 (gmt 0)

10+ Year Member



The problem with the Xoops is it has a habit of creating modules (which are needed to do anything) in subdirectories. So now I have two (unneeded) subdirectories to get rid of and a dynamic URL to clean up, so again, my need for mod rewrite it seems.