Having problems with mod_rewrite

Discuss practical ways rearrange URLs using mod_rewrite.

Having problems with mod_rewrite

Postby Karma » Mon Jul 21, 2008 12:42 am

Hi all,

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/?albuminfo=generic-album-title ---------> mydomain.tld/albums/generic-album-title/

mydomain.tld/?albuminfo=another-album-title ---------> mydomain.tld/albums/another-album-title/

mydomain.tld/?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/?songs=t ---------> mydomain.tld/songs/t/

mydomain.tld/?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 :-?

---------------------
RewriteEngine on
RewriteRule ^([^_]+)/([^/]+)/?$ /index.php?$1=$2&$3=$4 [L]
---------------------

Anyone?
Karma
 
Posts: 1
Joined: Mon Jul 21, 2008 12:32 am

Postby richardk » Tue Jul 22, 2008 10:06 am

Try
Code: Select all
Options +FollowSymLinks

RewriteEngine On

# /albums/generic-album-title/ --> /?albuminfo=generic-album-title
RewriteRule ^albums/([^/]+)/?$ /?albuminfo=$1 [QSA,L]

# /artist/example-artist-name/ --> /?artistinfo=example-artist-name
RewriteRule ^artist/([^/]+)/?$ /?artistinfo=$1 [QSA,L]

# /songs/t/ --> /?songs=t
RewriteRule ^songs/([a-z])/?$ /?songs=$1 [NC,QSA,L]

# /thesongtitle/45678/ --> /?song=thesongtitle&id=45678
RewriteRule ^([^/]+)/([0-9]+)/?$ /?song=$1&id=$2 [QSA,L]


I'm losing my images/style sheets

FAQ: Relative paths to images, JavaScript, CSS and other external/linked files are broken.
richardk
 
Posts: 8800
Joined: Wed Dec 21, 2005 7:50 am


Return to Friendly URLs with Mod_Rewrite

Who is online

Users browsing this forum: No registered users and 29 guests

cron