Closed Thread Icon

Topic awaiting preservation: PHP & Apache: Mod Rewrite vs Force Type and relative linking issues. (Page 1 of 1) Pages that link to <a href="https://ozoneasylum.com/backlink?for=13001" title="Pages that link to Topic awaiting preservation: PHP &amp;amp; Apache: Mod Rewrite vs Force Type and relative linking issues. (Page 1 of 1)" rel="nofollow" >Topic awaiting preservation: PHP &amp; Apache: Mod Rewrite vs Force Type and relative linking issues. <span class="small">(Page 1 of 1)</span>\

 
Cameron
Bipolar (III) Inmate

From: Brisbane
Insane since: Jan 2003

posted posted 11-24-2003 06:35

I'm setting up some search engine friendly URL's for a dynamic section of a web site and am wondering what method causes less server strain, mod rewrite (using simple regular expressions) or using a simple force type and doing the URI re-formatting inside PHP as per this evolt article on search engine friendly URL's.

I'm also having a few minor problems with relative links within these pages. Using either mod rewrite or force type the relative url's for the actual PHP scripts work just fine, but all relative URL's in the HTML page (hyperlinks, images, styles, javascripts etc..) are based from the point of the actual URI visible in the web browser. Is there any way to get around this with some mod rewrite magic? At the moment I've started recoding the HTML relative links to use the server root relative paths, /path_to_php_script/dynamic_url/.... as oppose to just ./dynamic_url/.... which works but surely there's a way to maintain one URL for both sides of the fence -- using absolute URL's is defiantly out of the question. Tracking and maintaining two separate URL paths for PHP includes and the templating system is a real pain.

Although after peeking at the source code for the GN discussion forum I'm not sure this is possible as that seems to be using server root relative paths as well.

Edit:
Why is it, after spending a whole night searching for a solution that I always seem to find my answer 5 minutes after I post the question to a message board. Found this on the www.webmasterworld.com forums:

quote:
The server only does what it is told - it looks for any resource at the URL requested by the browser. The browser requests a page, and then it requests each image on that page, and all requests are separate and independent. The browser, not the server, is responsible for resolving relative links on the pages it is rendering.



Which means I?m shit out of luck trying to maintain relative URL paths by simply using mod-rewrite, unless anyone has any possible solutions asside form doing lots of path juggling and URI mincing in PHP?

[This message has been edited by Cameron (edited 11-24-2003).]

Tyberius Prime
Paranoid (IV) Mad Scientist with Finglongers

From: Germany
Insane since: Sep 2001

posted posted 11-24-2003 10:11

don't know, but if you don't tell the server to redirect via [R], the browser should believe it's acessing your 'fake' url, and therefore base all it's request of it.

poi
Paranoid (IV) Inmate

From: France
Insane since: Jun 2002

posted posted 11-24-2003 10:40

Cameron: As I'm more confortable with URI re-formatting via PHP, I'd go for that solution. It's easy to set up and to use.
As for the relative links, there's no problem, I imagine your dynamic pages shares the same images, styles, javascripts ... so you can put them in a folder at the root of your domain i.e. /scripts/... or /images/...

Nonetheless, if you want to assign some images to a given dynamic page, you can use the same script that re-formats the URI and check the file type. If it corresponds to a picture ( or any attached file ) locate the requested file, set the MIME-TYPE in the HTTP headers and output the content of the file.

Cheers,

Mathieu "POÏ" HENRI

InI
Paranoid (IV) Mad Scientist

From: Somewhere over the rainbow
Insane since: Mar 2001

posted posted 11-24-2003 10:51

The poster has demanded we remove all his contributions, less he takes legal action.
We have done so.
Now Tyberius Prime expects him to start complaining that we removed his 'free speech' since this message will replace all of his posts, past and future.
Don't follow his example - seek real life help first.

Cameron
Bipolar (III) Inmate

From: Brisbane
Insane since: Jan 2003

posted posted 11-24-2003 11:38

Edit: Never mind. I'll just use force type and handle it all within PHP.

--------------------------------------------------------------------------------

Ok, I thought I had this sorted last night but I'm still getting some issues and I'm getting really confused about this now.

Ok, lest say the user goes to:
www.whatever.com/file_store/browse/images/boats/

and I want to translate that into:
www.whatever.com/file_store/files.php?a=browse&p=images/boats

I can do this ok using mod-rewrite, and all the include paths in the PHP file work just fine, but when the page is rendered all the style sheets, images and javascript stuff breaks.

At least I think I can... argh. Now nothing works. This is really starting to shit me. The more I work on this the more steps backwards I seem to be taking.

Anyways, when it was partly working, If I right click on an image and select "properties" the URL is gives in the rendered HTML page is: www.whatever.com/file_store/browse/images/boats/file_store_data/templates/d efault/folder.gif

Which simply doesn't exist.

Yet in the actual HTML source of the rendered page:
<img src="file_store_data/templates/default/folder.gif" alt="Small Folder Icon" />

The actual location of the image is: www.whatever.com/file_store/file_store_data/templates/default/folder.gif

Which seems to be the same problem this person had: http://www.codemonkeyx.net/forums/viewtopic.php?p=3840 although his solution was to use a <base href=""> tag which is a really really ugly solution IMHO.

I'm sure this can be done with mod rewrite but I can never get my head around any of the apache manuals, which require a manual on how to read the manual... grrr.

[This message has been edited by Cameron (edited 11-24-2003).]

[This message has been edited by Cameron (edited 11-24-2003).]

Emperor
Maniac (V) Mad Scientist with Finglongers

From: Cell 53, East Wing
Insane since: Jul 2001

posted posted 11-25-2003 02:01

I'd use mod-rewrite as ForceType can get messy and mode-rwite is non-destructive but that sjust my preference - you need to find a solution you like and really explore all the potential

You will need to make all your links 'absolute' to the root i.e. no more ./, ../, etc.

___________________
Emps

The Emperor dot org

Cameron
Bipolar (III) Inmate

From: Brisbane
Insane since: Jan 2003

posted posted 11-25-2003 09:46

Yeah, I've decided to use mod rewrite as force type was causing some other isues. I've also discovered that about the links, and I've changed them but that really shouldn't be the case.

I should be able to use a RewriteCond to excluse any request uri that asks for files out of a particular directory -> the direcotry where all the data files, images and css files for the web applicaiton reside. I've seen this done before and seen examples for mod_rewrites that do just that and the people that write them claimed that they worked. But not for me. I'm following the regex syntax to the letter and nadda. It's as if my server completly ignores the RewriteCond instruction. And seeing as this is the third full day I've wasted trying to find a solution to this problem (25+ hours I could have spend enjoying my holidays), I'm seriously thinking it's just not worth the trouble.

Although I'm starting to suspect somethig is really screwy with my server. Even the most basic and specific regex's will either match everything or nothing. It just plainly doesn't make sence for things to be happening the way they are. I've even set up situations similar to various tutorials I've found online and *none* of them even came close to working. Yet it sometimes kinda works when I fiddle around with parts here and there or oversimplify the test conditions causing endless rewrites so I know the module s installed.

Edit:
Alright, I have a working solution now. Using mod rewritw with a handfull of different rewrite rules instead of trying to everything with just one. Turns out I was using the wrong regular expression synax anyways *slaps self*.

[This message has been edited by Cameron (edited 11-25-2003).]

« BackwardsOnwards »

Show Forum Drop Down Menu