Forum Moderators: phranque

Message Too Old, No Replies

Help with Rewrite of complex URL's

mod_rewrite of complex URL's

         

nicklnz

12:45 am on Oct 17, 2007 (gmt 0)

10+ Year Member



I sure I'm being a numty here but hopefully someone can help me here, I've been struggling for a while now and can't seam to find an answer, or understand how to do this.

We have the following url in a dev envrionment:

[192.168.2.30...]

Where example is a sub-directory below the default site and main is main.php

We'd like to be able to drop main from the URL so create a rewrite to translate:

[192.168.2.30...]

back to

[192.168.2.30...]

Then when we roll this in to production do the following:

www.example.co.nz/Very%20Nice%20Hotel/Overview/Hotel%20Services/

rewritten to

www.example.co.nz/main/Very%20Nice%20Hotel/Overview/Hotel%20Services/

Bascially we just want to get rid of main out of the URL

Look forward to your responses

[edited by: jdMorgan at 5:44 pm (utc) on Oct. 17, 2007]
[edit reason] Examplified per Terms of Service [/edit]

jdMorgan

5:59 pm on Oct 17, 2007 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



The main problem with this approach is that you must identify which URLs are to be rewritten and which are not -- Otherwise, all URLs for resources in your root directory will end up being rewritten to the /main subdirectory.

So, for example, your robots.txt file would have to be physically relocated to /main/robots.txt -- Obviously not what you want.

Therefore, the question is --given the example URLs above-- how will you identify all URLs for resources that are actually located in /main? It may be simple, for example, if they all start with "Very%20" or it may require a list of URL-paths -- which you would then have to maintain in the code over the long term. Or, if you have many files and subdirectories in main, it may be so complex and/or inefficient as to be of questionable utility.

To ease discussion, just remember that all mod_rewrite execution decisions are based on the URL requested by the client, and not (usually) on any other factors, such as the filepaths to which those URLs ultimately resolve.

Another point --somewhat unrelated to your question-- is that using spaces in your page names is just a very bad idea. It results in very%20ugly%20and%20hard%20to%20read%20URLs, makes coding RewriteRules literally twice as difficult, and can lead to knock-on effects that only make the URLs uglier and the rules even more difficult when you try to correct those. I suggest you seriously consider using hyphens (not underscores) or eliminating the spacing altogether. Hyphens are to be strongly preferred.

Jim

g1smd

8:02 pm on Oct 17, 2007 (gmt 0)

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



When you set up your rewrite, make sure that the "real" location of the files is not web accessible. If you fail to do that you create a Duplicate Content issue. Make sure that all of the pages of the site reference the URLs that you do want to be indexed in all of the links. If necessary use Xenu LinkSleuth or similar to check the site navigation for errors. Finally, use only hyphens or dots for word spacers. Avoid spaces and underscores.