View Full Version : rewrite problems
I've been trying to do a URL rewrite with .htaccess
I searched the forums and tried many variations listed - all with no success.
Here's what I currently have in my .htaccess file
RewriteEngine on
RewriteRule ^([^/]+)/([^/]+)/?$ index.php?content=$1&vehicle_id=$2
I have also tried using the various URL Rewrite tools on the web (the ones where you enter the URL and it spits out the .htaccess) and the generated code doesn't work either.
A nudge in the right direction would be appreciated.
Thanks
Basil
04-12-2008, 04:28 AM
What are you trying to match?
This is what you're saying..
- Start at the beginning of the string ^
- Match any character that is not a "/" between one and unlimited times ([^/]+)
- Match the character "/" literally /
- Match any character that is not a "/" between one and unlimited times ([^/]+)
- Match the character "/" literally between zero and one times /
- End at the end of the string $
That would rewrite "foo/bar" with an optional trailing slash to "index.php?content=foo&vehicle_id=bar"
Hmmm, sort of the opposite of what I was planning for.
so how would I reverse that..
from the current:
index.php?content=foo&vehicle_id=bar
to
foo/bar/
Thanks
I gave this a try (from one of the URL Rewrite Tools):
RewriteRule content/(.*)/vehicle_id/(.*) .?content=$1&vehicle_id=$2
should rewrite to:
/content/feature/vehicle_id/54/
But that doesn't seem to work either.
djmatt
04-15-2008, 07:09 PM
I've just begun dabbling in htaccess but I think what Basil was saying by
That would rewrite "foo/bar" with an optional trailing slash to "index.php?content=foo&vehicle_id=bar"
you would see www.mysite.com/foo/bar
but you would actually go to:
index.php?content=foo&vehicle_id=bar
which is the clean way of handling messy variables.
I did a site that has lots of users. Rather than using http://www.newmenu.org/candidates.php?candidate=jaysweeney
you just type in:
http://www.newmenu.org/jaysweeney
and it takes you to the same page
My rewrite is:
Options + FollowSymlinks
RewriteEngine on
RewriteRule ^([A-Za-z0-9-_]+)/?$ candidates.php?candidate=$1 [L,NC]
My rewrite is:
Options + FollowSymlinks
RewriteEngine on
RewriteRule ^([A-Za-z0-9-_]+)/?$ candidates.php?candidate=$1 [L,NC]
That gives me a 500 internal error message (I think due to the Options + FollowSymlinks).
With the Options line out and RewriteRule ^([A-Za-z0-9-_]+)/?$ index.php?content=$1 [L,NC] it still did nothing.
Thanks.
microinfosoft
04-23-2008, 05:24 PM
Hi can anyone tell me how to write htaccess for bluhost.I have another server there my code is running properly but this code is not running here
htaccess code
<IfModule mod_php4.c>
RewriteEngine On
RewriteBase /
RewriteRule test1.html$ test.php
RewriteRule test/page-(.*).html$ test2.php?page=$1
</IfModule>
Now when i am trying to access page by url
http://www.domain name.com/test1.html
or
http://www.domain name.com/test/page-1.html
It is saying page bot found.But page is there.
This code is running on my other server but i dont kno it is not running here.
If you know the reason then please provide me the solution.
Thanks
djmatt
04-28-2008, 05:00 PM
I found this handy cheat sheet:
http://www.ilovejackdaniels.com/mod_rewrite_cheat_sheet.pdf
Ah HA!
I've been messing around with this on and off and figured out my problem.
I was expecting the "web magic" to change my site and voila! friendly URLs.
It had been working correctly, except I would put in the .htaccess info, reload the page and none of the links seemed to be changed.
Then I found this on the forums:
I repeat:
"Also understand that only incoming URLs will be rewritten. You need to write your own outgoing URLs in the format you desire, then expect mod_rewrite to rewrite them when someone clicks on them."
I just need to cleanup some of my URLs. Thanks :)
-
Powered by vBulletin® Version 4.1.10 Copyright © 2012 vBulletin Solutions, Inc. All rights reserved.