Forum Moderators: phranque
Here's what I'm trying to do. I have a dynamic URL appearing on the homepage (index.php) of my site:
http://www.example.com/news.php?id=23
I want the URL to rewrite to look like this:
http://www.example.com/news/dynamicarticletitle/23
The dynamicarticlename is pulling from the database along with the article id number.
I've tried every which way using Rewriterule to get this to work but haven't been able to. I got it working once with just the id number and not the article name, but then the rest of the images on the site had their paths rewritten and were broken.
Here's the latest pass in .htaccess to get it working only with the id number, to keep things simple:
RewriteEngine on
RewriteRule ^news/([0-9]*)/$ news.php?id=$1 [L]
And here's the html:
<a href="news/id">
Simply enough. Any advice would be appreciated. I suspect this is a 10 second fix. Thanks!
You have a couple of choices: You can either change the links for included objects on your pages to server-relative or canonical form, or you can add a rule to rewrite the image requests to their actual locations. Examples of server-relative and canonical image links are <img src="/images/logo.gif"> and <img src="http://example.com/images/logo.gif">
Jim
Know of any good examples I can go off of? I've looked around and haven't found anything directly applicable yet.
Here is an example on the same domain:
/images/example.gif
Here is an example on the main domain (the site I'm working off is a sub-domain):
[example2.com...]
RewriteRule ^news/([0-9]*)/?$ /news.php?id=$1 [L]
Jim
[edited by: jdMorgan at 4:47 pm (utc) on Nov. 30, 2007]
BUT, I did play around some more and figured out that relative paths to images on the same sub-domain do, in fact, work. It's the images I'm calling from the main domain and another sub-domain that are not working.
I could shift image locations around and fix that issue, but if you know off the top of your head an easy fix example in .htaccess, I'd love to know it for future reference.
Thanks!