Forum Moderators: phranque
Could really do with some help with a mod_rewrite. I'm aiming to re-structure my URLs in an existing site but I'm having problems getting things working, I'm looking at rewriting the following:
mydomain.tld/index.php ----------> mydomain.tld/
index.php?albuminfo=generic-album-title ---------> mydomain.tld/albums/generic-album-title/
index.php?albuminfo=another-album-title ---------> mydomain.tld/albums/another-album-title/
index.php?artistinfo=example-artist-name ---------> mydomain.tld/artist/example-artist-name/
Plus the more tricky part which is what I'm really having problems with:
mydomain.tld/index.php?songs=t ---------> mydomain.tld/songs/t/
mydomain.tld/index.php?song=thesongtitle&id=45678 ---------> mydomain.tld/thesongtitle/45678/
This is what I have for the top part, but I'm losing my images/style sheets :c/
---------------------
RewriteEngine on
RewriteRule ^([^_]+)/([^/]+)/?$ /index.php?$1=$2&$3=$4 [L]
---------------------
Anyone?
[edited by: Karma at 1:40 pm (utc) on July 17, 2008]
Be aware of two things: First, you may need to exclude images, stylesheets, external JavaScript files, and common files such as robots.txt, /w3c/p3p.xml, labels.rdf, etc. from being rewritten to index.php. Second, if you use page-relative linking to include these objects on your pages, you may need additional code to correct their URLs when requested, or you may want to use server-relative or canonical object links on your pages instead.
The solution is complicated by the fact that you have exposed (linked to) "/index.php" instead of just "/". This is going to cost you some extra coding/performance.
Jim
---------------------
RewriteEngine on
RewriteRule ^([^_]+)/([^/]+)/?$ /?$1=$2&$3=$4 [L]
---------------------
I link to my css and images using:
="/css/style.css"
[edited by: jdMorgan at 1:24 am (utc) on July 18, 2008]
[edit reason] Speling [/edit]
index.php?albuminfo=generic-album-title ---------> mydomain.tld/albums/generic-album-title
index.php?albuminfo=another-album-title ---------> mydomain.tld/albums/another-album-title
index.php?artistinfo=example-artist-name ---------> mydomain.tld/artist/example-artist-name
mydomain.tld/index.php?songs=t ---------> mydomain.tld/songs/t
By using this:
RewriteEngine on
RewriteRule albums/([^/]+) /?albums=$1 [L]
RewriteRule artist/([^/]+) /?artist=$1 [L]
RewriteRule songs/([^/]+) /?songs=$1 [L]
However, I still can't get the tricky part working at all:
mydomain.tld/?song=thesongtitle&id=45678 ---------> mydomain.tld/thesongtitle/45678
I tried this, it's probably stupid and makes no sense:
RewriteRule ([^_]+)/([^_]+) /$1/id=$2 [L]
Anyway, thanks for the help provided earlier.
[edited by: Karma at 2:38 pm (utc) on July 21, 2008]