Jump to content

help with mod rewrite request: From /page.html to /category/page


Recommended Posts

Hello everyone.

I couldn't find the exact answer on similar threads; Apologies if the topic has been discussed too much before.

 

I'm trying to use mod rewrite to achieve the following outcome:

 

1. Current situation:

page URL: www.MyDomain.com/Football.html

/images

/includes

both directories above reside on the web root directory. all references to them from football.html are relative (i.e. /images/pic.gif or /includes/header.html)

 

2. Desired situation:

page URL: www.MyDomain.com/Games/Football

 

/images

/includes

remain in the same place.

All relative links within the page (football.html) should still point to www.MyDomain.com/link.html and NOT MyDomain.com/Games/Link

(check out www.Backgammon.Org for the solution I'm after).

 

Obviously, a single RewriteRule didn't do the job for me.

Guys, I need your help. It's way over my head. How can I solve it?

 

Thanks in advance.

 

From the information in scenario 1) I can't see why you'd have a problem with links in scenario 2). Again, from the information given, this would look merely like an HTML page-editing issue regarding how you've specified your links.

 

If there's a problem then I think you've missed out some important information somewhere

 

Also, I can't see how the backgammon site illustrates the problem :/  ???

thanks for the reply.

1. the backgammon site shows how I want to implement things.

2. currently, if I redirect mydomain.com/football.html to mydomain.com/games/football/, all the relative links within the html will bear the directory "/games". this means that all "included" header and footer links will now contain a "/games/link.html" instead of just "link.html". Also, the browser tried to obtain the include and image files from "/games" location which, of course, doesnt exist.

 

perhaps I am indeed missing the point and not implementing it correctly.

 

I tried to use directories and '../' referrals in the relative paths for all links and files ('../images/image.gif', '../includes/footer.html' etc) but the browser doesn't recognize them. If I'm able to make it work with '../', then I guess I can dismiss the mod rewrite issue and solve it more simply. any suggestions?

I'm still flummoxed with some of this and I'm not sure I have the whole picture.

 

What makes you sure it's the browser which has issues properly handling relative paths such as "../games" ?  Which browser are you testing on and having problems with? Is it just one browser or all?. Do you have any test content live yet which others on here could check out ?

 

Bear in mind that a simple answer to creating a fake root mapping for a given folder might be to use the Alias directive with a "/" prefix.

This is how (or should be, how) your "/error/" pages work across all of the sites on any server.

You can access /error/whatever.html from anywhere.

 

Say you had one set of widgets (icons graphics) which you want to map as "root" you can declare an alias to a physical path. This may be a simpler solution than doing an awful lot of fiddling with page content and would make the content root-global across all sites you operate - and also make page-editing a lot easier.

http://httpd.apache.org/docs/2.0/mod/mod_alias.html

 

Linux...(fingers crossed the example is correct - I'm not a Linux expert)

Alias /widgets /var/www/htdocs/content/widgets

 

Win32 ...

Alias /widgets "c:/www/htdocs/content/widgets"

 

You could then access "/widgets/blue.gif" from any page on any site but browsing for resources during page editing might be problematic!. Depends how you generate your content.

 

Then again... any solution offered might be wrong as I'm not entirely convinced that you're not making perhaps some wrong assumptions about the way browsers or HTML linking works. Worth checking...

 

Try this http://www.w3.org/TR/html401/struct/links.html specifically http://www.w3.org/TR/html401/struct/links.html#h-12.4.1 (document base)

 

If you are having problems with upward references then you might possibly have unintentionally blocked directory traversals with ".." elsewhere without realising the consequences - e.g. using mod_security or another security rewrite rule.  Not aware of any browsers which would have problems handling upward directory traversals though. I can't recall the last time I purposely used "../"

 

.. or ../  GO UP and append path (if you use this a lot you might consider using an Alias)

<nothing> append to current base path

/  ROOT  map content path to server root

 

Is there anything specific on the back gammon site which illustrates an issue I can check?

I would also recommend testing on serveral browsers esp IE, Firefox, Seamonkey etc.

An awful lot of this advice would depend on what you find convenient and how you generate your pages.

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.