Forum Moderators: phranque
I'm having issues with .htaccess files to change dynamic PHP urls on my
page. Here's what I'm using:
RewriteEngine On
RewriteRule ^reviews/([0-9]+)/»
reviews/displayreview.php?id=$1
RewriteRule ^reviews$ index.php
Essentially I'm running this in /matt/dev/ (off root). I want to change
urls like /reviews/displayreview.php?id=$foo into /reviews/foo/ ..?
When I apply the above code I just get 500 errors.
While we're on the subject, I also want to redirect all urls to the old
system into the new one, eg:
[mysite.com...]
into:
[mysite.com...]
or even better:
[mysite.com...]
I've tried this several time after following tutorials and never
managed to succeed; can anyone help?
RewriteEngine On
RewriteRule ^reviews/([0-9]+)/?$ reviews/displayreview.php?id=$1 [L]
RewriteRule ^reviews/?$ index.php [L]
You mentioned in your description you wanted to rewrite /reviews/displayreview.php?id=$foo into /reviews/foo/. Well you can't do this as it is, id's aren't magically transformed into their corresponding db text. But i'm sure you can pick it up from here :)
I used that code and modified it for other pages, but got a weird problem.
Here's the code:
RewriteRule ^features/([0-9]+)/([0-9]+)/?$ features/displayfeature.php?id=$1&page=$2 [L]
RewriteRule ^features/?$ features/index.php [L]
This is the format of my links:
mysite.com/matt/dev/features/displayfeature.php?id=63&page=0
I tried accessing the url like:
mysite.com/matt/dev/features/63/0/
This displays the content and everything, but without a css style! Very odd. If I access the page with the above (lengthy) url it displays fine. Is this some relative path issue?
The weird part is, all the other links are in subfolders as well. Like, here's my structure:
matt/
matt/dev/
matt/dev/reviews/
matt/dev/news/
matt/dev/features/
The links for reviews and news both work fine, which doesn't seem to make any sense!
(I sometimes ask a lot of questions before jumping into coding a solution. It avoids confusion, and also metaphorically, it avoids putting a band-aid on a major-trauma wound.)
Jim
RewriteRule ^features/([0-9]+)/([0-9]+)/?$ /features/displayfeature.php?id=$1&page=$2 [L]
RewriteRule ^features/?$ /features/index.php [L]
As a result, you may need a specific ruleset to steer the CSS and image requests to the proper 'real' file locations... Depends on how you've set things up.
Another solution would be to make your links server-relative, rather than page-relative, i.e. <img src="/logo.gif">
Jim
I tried that code, just gives a "No input file specified." error.
I am using relative links for css and stuff, but surely they should still work, as:
a) the same code works for the reviews page, which is in a subfolder off /matt/dev/ just like features
b) the url being /matt/dev/features/ (with a reference to ../style.css) shouldn't change anything, as the old url was just matt/dev/features/displayfeature.php
Really odd!
If the browser asks for /features/63/0/ and that page contains a link to <img src="logo.src", then that image will be requested from /features/63/0/logos.src. If you don't rewrite the image request or root it to your "Home page" directory, the request is going to fail.
Jim
The features stuff has a second value in the url (it corresponds to page numbers) so everything is being misrouted.. of course! Damn. At least that explains the issue. It'll be too much hassle to change all the relative paths (I php include the same header/footer for every site page, and my css) so I'll just not use url rewriting for the features section.
Thanks a lot for the help!