SitePoint Sponsor |
|
User Tag List
Results 1 to 5 of 5
-
Sep 23, 2009, 06:33 #1
- Join Date
- Jun 2008
- Location
- Gloucestershire, UK
- Posts
- 197
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
Files not loading after mod_rewrite
Hello,
I've started building an online shop using a modularized system, where I'm adding all of the module's content to a variable and echoing out that variable in a single template.
I'm using Apache Mod Rewrite to change URL's from "site.co.uk?p=home" to site.co.uk/home using the rewrite rule below:
RewriteRule ^([a-z_]*)$ /index.php?p=$1 I still need to modify it to take uppercase and numbers.
My problem is that I need to pass data through the URL's so I've tried the following:
RewriteRule ^categories/([0-9]*)$ /index.php?p=categories&cat_id=$1 [L]
RewriteRule ^([a-z_]*)$ /index.php?p=$1
If I try site.co.uk/categories everything's fine but if I try site.co.uk/categories/7 to pass some data the page doesn't load the CSS file (even though the source code looks ok) and the images, but does receive the number.
Can anyone see where I'm going wrong?
I Should add that if I use site.co.uk/index.php?p=categories&cat_id=7 everything works as it's meant to.
Cheers,
Jon
-
Sep 23, 2009, 09:04 #2
- Join Date
- Jan 2006
- Posts
- 15
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
turning 'site.co.uk/home' into 'site.co.uk?p=home'
use:
RewriteRule ^home$ site.co.uk?p=home [NC,L]
make this dynamic with
RewriteRule ^([a-z0-9_-]+)$ site.co.uk?p=$1 [NC,L]
try to use + quantifier. the + means 1 or more. * means 0 or more!
RewriteRule ^categories/([0-9]+)[/]?$ /index.php?p=categories&cat_id=$1 [L]
Hope that helps...Free Code Source, Tutorials, Tips & Tricks - Openzu.com
Professional Website Development - Wired IDS Ltd
. BSc (Hons) (Computer Science), MBCS
-
Sep 23, 2009, 09:21 #3
- Join Date
- Jun 2008
- Location
- Gloucestershire, UK
- Posts
- 197
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
Thanks for your help but there are still no files loading.
if you want to take a look...
https://lxplesk204.fm.netbenefit.co....k/categories/2
Should look like:
https://lxplesk204.fm.netbenefit.co....ories&cat_id=2
Please remember most of the links are dead at the moment (trying to get mod_rewrite working properly first).
You will get a warning that there is something wrong with the security certificate, it's only a preview so there's nothing to worry about.
Cheers,
Jon
-
Sep 23, 2009, 17:40 #4
- Join Date
- Jan 2002
- Location
- Australia
- Posts
- 2,634
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
Usually this is because the browser loads CSS/JS files relative to the URL of the page. So if the address is example.com/products/helicopters/apache and your source code references a CSS file at css/style.css then the browser resolves that to example.com/products/helicopters/apache/css/style.css, which of course is a 404 because those directories don't really exist on your server.
You can either add a <base href='http://example.com'> tag to your document (so the browser loads relative to that), or use absolute links in your HTML.
-
Sep 24, 2009, 01:51 #5
- Join Date
- Jun 2008
- Location
- Gloucestershire, UK
- Posts
- 197
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
Thanks for that, I've been scratching my head over that one for hours.
Cheers,
Jon
Bookmarks