.htaccess rewrite not working

Hi I have had a look at alot of posts on this forum and other throughout the web.
I am trying to get the .htaccess mod rewrite to work on my site.
I was wanting to set it up so that it would create more seo friendly urls from my pages but thought I should try to get something simple working first.

The code I have in my .htaccess file is below:

RewriteEngine on
RewriteRule ^/([a-zA-Z0-9]+)$ $1.php [L]

I thought this should remove all .php file extensions on my site but it doesn’t work!

Can anyone help with this please? I don’t get any errors I’ve cleared the cache on my browser but still nothing. Th e.php file extensions still show!

Any help very much appreciated with this.

Thanks in advance.

The .htaccess doesn’t remove the .php from the links in your site, that’s your job to change those yourself in the source. All the .htaccess does is serve /contact.php when /contact is requested for example.

OK I think I might be getting confused with this a little. What I am trying to do is get my site to generate more seo friendly url’s. For example the way the site is currently set up it has links such as:

http://www.mysite.com/details.php?BikeId=22223758

I would like this url to display something like:

http://www.mysite.com/used-bikes/BMW/G650/2007/

All those variables I can get via a php script but I have no idea how to set up my .htaccess file so that this will work.

Could you help me with this please?

If you’re completely new to .htaccess and RewriteRules I’d suggest you start by reading this article.

Once you’ve read that, if you have any specific questions about it, don’t hesitate to come back here and ask them :slight_smile:

Thanks very much for the link, thats made this alot clearer for me.

Right I’m still confused with this. I have read the article you pointed me to did the tests and tried the examples and most of them make sense. I still don’t understand how I can get this to work.
Can you please give me some help with the url’s I posted?

Sorry but I’m just a little confused with this. The article you pointed me to seems to show how to do the opposite of what I’m looking for, which I don’t understand.

Would it be easier if I had my original link set up like this:

www.mysite.com/details.php?Make=BMW&Model=G650&Year=2007

to then convert into this:

www.mysite.com/used-bikes/BMW/G650/2007/

Yes that would definitely be easier!

Ok the php part of this is the bit I have no problem with. I can set that up but I still can’t get my head around the .htaccess code to make it work.

Sorry for being a bit thick wit this. U sound like you know alot about this can you help me please?

Why don’t you give a try writing a RewriteRule and we’ll take it from there?
It’s not very hard for the case you want :slight_smile:

I like your learn from experience method… I’ll try. :slight_smile:

Right I’m trying to work this out. In the examples I’ve given for what I’m looking to do should my links look like so:

<a href=‘/BMW/G650/2007/’> more info ></a>

I’m trying to work out why what I have is not working, I think I have the .htaccess set up wrong but can you tell me if what I’ve put here should work when I get the .htaccess file working correctly so I know that the link structure I have is at least right?

Yes the link structure looks okay to me. I myself don’t use uppercase in URLs, but that’s just personal taste and there’s nothing against it really :slight_smile:

ok cool, thanks for that. I’ll keep working on the RewriteRule to see if I can figure this out.
Might be back for some advice in a bit if I can’t get this to work.

Thansk again for your patience.

I thought I had it worked out but it still doesn’t work!!

My .htaccess file now looks like this:

RewriteEngine on
RewriteRule ^([a-zA-Z_]+)/([a-zA-Z_]+)/([a-zA-Z_]+)$ details.php?make=$1&model=$2&year=$3 [L]

When I click a link link this <a href=‘/BMW/G650/2007/’> more info ></a>
I get a not found error page.

When I click on a link like this /details.php?make=BMW&model=G650&year=2007
I am taken to that page, the URL in the address bar doesn’t get replaced.

Where am I going wrong with this??

Ooooow, you’re so close!

([a-zA-Z_]+)/([a-zA-Z_]+)/([a-zA-Z_]+)
/BMW/G650/2007/

:slight_smile:

Ahhhh! I now have this and its not working either :frowning:

RewriteEngine on
RewriteRule ^([a-zA-Z_]+)/([a-zA-Z_]+)/([a-zA-Z_]+)/$ details.php?make=$1&model=$2&year=$3 [L]

Looks good to me though! Does this work:


[B]Options +FollowSymLinks[/B]
RewriteEngine on
RewriteRule ^([a-zA-Z_]+)/([a-zA-Z_]+)/([a-zA-Z_]+)/$ details.php?make=$1&model=$2&year=$3 [L]

or this


RewriteEngine on
RewriteRule ^[B]/?[/B]([a-zA-Z_]+)/([a-zA-Z_]+)/([a-zA-Z_]+)/$ details.php?make=$1&model=$2&year=$3 [L]

or this


RewriteEngine on
RewriteRule ^([a-zA-Z_]+)/([a-zA-Z_]+)/([a-zA-Z_]+)/$ [B]/[/B]details.php?make=$1&model=$2&year=$3 [L]

?

I keep getting 404 not found errors on all of those. Should the links I’m getting people to click onto be like this /BMW/G650/2007/ or like this details.php?make=BMW&model=G650&year=2007

The links people click on (the <a href>) should be like /BMW/G650/2007/

Are you sure mod_rewrite is installed and enabled on the server?

You can do a little test. Put this in the .htaccess :


Options +SymLinks
RewriteEngine On
RewriteRule test http://www.google.com/ [L,302]

Then go to a URL on your site that contains “test” (doesn’t matter how or where). If it takes you to google.com mod_rewrite is installed and works, if it doesn’t mod_rewrite is either not installed or disabled.