|
-
Feb 23rd, 2010, 03:42 AM
#1
Thread Starter
Frenzied Member
[RESOLVED] Pretty URL's
Hi,
I'm giving pretty URL's a shot, but it's giving me headaches already.
The setup is .htaccess with the following content:
Code:
RewriteCond %{SCRIPT_FILENAME} !-d
RewriteCond %{SCRIPT_FILENAME} !-f
RewriteRule ^([^\.]+)$ index.php?file=$1 [NC,L]
And in PHP retrieving $_GET['file'].
It kinda works, but the problem I'm facing is that when the path is deeper than 0 (e.g. /foo/bar) images and CSS don't work because the paths are incorrect (like img/foo.png).
Now rather than hardcoding in the paths to the images and css, I was wondering if there is a way of tweaking the .htaccess a little bit more to fix that.
Any other solutions would also be appreciated.
Thanks
Delete it. They just clutter threads anyway.
-
Feb 23rd, 2010, 05:20 AM
#2
Re: Pretty URL's
Why not use absolute paths to images and CSS?
http://webdesign.about.com/od/beginn.../aa040502a.htm
For example:
Instead of ../../css/screen.css
Use /css/screen.css
I don't think this is a .htaccess problem, it's a problem with your paths to your resources.
-
Feb 23rd, 2010, 09:14 AM
#3
Re: Pretty URL's
yeah, I'd do what ILMV suggested. either store a constant that defines an absolute path (including your domain), or use the types of absolute paths that ILMV described.
I'm sure there's something you might be able to do that captures anything with a "css/" or "img/" directory and then rewrites to the correct directory, but it's a little unnecessary when you can solve the problem so easily by prepending a slash onto your URLs.
-
Feb 23rd, 2010, 10:08 AM
#4
Re: Pretty URL's
Many years ago (before I knew about absolute URLs) I used a crazy complicated bit of PHP to calculate how many ../'s I needed for my resource links.
Not only are absolute URLs a bajillion times more effective but it increases portability, say you want to copy your design to a sub domain, if your resources directly refer to the domain they will be useless under a different address.
In my current job we are being ultra cautious to make our project as portable as possible, because we don't know if one of our partner organisations are going to want this in a sub domain of their corporate URL, or if their going to want to use Oracle instead of PostgreSQL.
Think portability!
-
Feb 23rd, 2010, 05:54 PM
#5
Thread Starter
Frenzied Member
Re: Pretty URL's
Maybe I should've added that I'm building a little cms with templates and all.
Portability was pretty much the issue.
Imagine I'd have a complete site in a subdirectory which I do in localhost;
http://localhost/foo/bar.php
For the template, hardcoding in the URL would be a no-go as that would vary on systems and pretty much destroy the portability.
But I've worked out that the base path should be a general setting so I can glue that in front of the url's that would fail otherwise.
(I'm having difficulties building this sentence, hope you understand it )
Anywany, thanks for the input!
Delete it. They just clutter threads anyway.
-
Feb 23rd, 2010, 06:14 PM
#6
Re: [RESOLVED] Pretty URL's
Yes, the typical solution is to have a base URI for your product, which is itself an absolute URI.
There's also a HTML base tag, which has its own set of pitfalls.
-
Feb 23rd, 2010, 06:26 PM
#7
Thread Starter
Frenzied Member
Re: [RESOLVED] Pretty URL's
Although I don't give a sh about IE6 users, I think it should be done server-side.
But nice tip, didn't know that one.
Delete it. They just clutter threads anyway.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|