Rewriting / directories / extension less urls help needed!

Discuss practical ways rearrange URLs using mod_rewrite.

Postby richardk » Mon Jul 07, 2008 1:52 pm

Try adding this to the end
Code: Select all
# Make sure /test/directory/filename.php exists.
RewriteCond %{DOCUMENT_ROOT}/test/$1$2.php -f
# Make sure it's in the format /optional-directories/filesname/filenamenumbers.
RewriteRule ^(.+/)?([^/]+)/\2([0-9]+)$ /test/$1$2.php?id=$3 [QSA,L]
richardk
 
Posts: 8800
Joined: Wed Dec 21, 2005 7:50 am

Postby whitenoise » Mon Jul 07, 2008 2:25 pm

Thanks again Richard. I've tried that code and its so nearly works! I see the .php?id=001 content, but my image that is on this file is missing. Looking at where the page is looking for the image it is:

www.example.com/test/directory/images/d ... /xx001.jpg

The image does not exist here. It lives in the same place its being linked to in the code:

www.example.com/test/images/directory/d ... /xx001.jpg

It looks like this new rewrite rule is rewriting the path for the jpg. Is a "if its not a jpg then do this" needed?
whitenoise
 
Posts: 9
Joined: Fri Jun 27, 2008 2:47 am

Postby richardk » Mon Jul 07, 2008 2:30 pm

What's the path in the source of the page? Is it relative? If it is: Relative paths to images, JavaScript, CSS and other external/linked files are broken.

All the rules check if it's a PHP file or a directory, it shouldn't match other files.
richardk
 
Posts: 8800
Joined: Wed Dec 21, 2005 7:50 am

Postby whitenoise » Tue Jul 08, 2008 12:46 pm

Yeah that was the issue.

Many, many thanks for all your help!!!! :D
whitenoise
 
Posts: 9
Joined: Fri Jun 27, 2008 2:47 am

Previous

Return to Friendly URLs with Mod_Rewrite

Who is online

Users browsing this forum: No registered users and 27 guests

cron