Hey all,
I have been searching and searching no luck yet.
I think what i have come up with is using apaches rewrite map, but clueless as to where to begin.

Here is the situation I have.
I have a url
http://www.somesite.com/post.php?id=13

and want to turn it into a SEO friendly url like
http://www.somesite.com/{dynamic_article_title}.php

The title is being pulld from a MySQL table.

Any suggestions as to where I should start or possible examples?
Am I on the right track with Rewrite map?

Thanks in advance!

Hey all,
I have been searching and searching no luck yet.
I think what i have come up with is using apaches rewrite map, but clueless as to where to begin.

Here is the situation I have.
I have a url
http://www.somesite.com/post.php?id=13

and want to turn it into a SEO friendly url like
http://www.somesite.com/{dynamic_article_title}.php

The title is being pulld from a MySQL table.

Any suggestions as to where I should start or possible examples?
Am I on the right track with Rewrite map?

Thanks in advance!

First you need to write your php script in such a way that instead of article id you can pass an article title.
For example instead of post.php?id=13
it should be post.php?id=my_article_title_goes_here

Your php script will then replace underscores with spaces and then pull the article from database using the title instead of article ID.

Once your php script works, you can add a rewrite rule to .htaccess or httpd.conf

RewriteRule ^/([a-zA-Z_\-]+)/\.html$ /post.php?a=$1 [QSA,L]

See this - you can even use the .html extension in your url to make it really look like a static url

Thank you so much! I didnt even think that. Thanks for the quick response also.

Im so confused on this mod_rewrite..
I am reading all these guides but they all have me confused

RewriteRule ^([A-Za-z0-9-]+)/?$ article.php?name=$1 [L]

Is the first portion(the pattern) checking the second? and then how does it knw what to swap it to?

Uncle's Smiths answer didnt work either and this has gotten me all messed up!

I have been testing a simple htaccess

Rewrite Engine on
RewriteRule ^page/.htm$ /new_page.htm

And this doesnt even work for me.. I am using Hostgator. I have contacted them and tehy said mod_rewrite is on and that I put it in the right spot. They said something about PHPsuexec but after research I believe is irrelevant to what i want to do. Anybody got suggestions to get this thing working?

Im so confused on this mod_rewrite..
I am reading all these guides but they all have me confused

RewriteRule ^([A-Za-z0-9-]+)/?$ article.php?name=$1 [L]

Is the first portion(the pattern) checking the second? and then how does it knw what to swap it to?

Uncle's Smiths answer didnt work either and this has gotten me all messed up!

First thing - make sure the rewrites are enabled on your server. If it's not, then you will be just wasting your time.

Second, even if rewrite rules are enabled, make sure they are allowed in .htaccess file. Sometimes you are limited to which directives are allowed in the .htaccess

Best thing to do is to put rewrite rule inside the apache <virtualHost> container in the httpd.conf

Now for your question
if you want your rule to work exactly for a this type of url:
http://www.somesite.com/{dynamic_article_title}.php

then change my first suggestion to this:
RewriteRule ^/([a-zA-Z_\-]+)\.php$ /post.php?a=$1 [L]

Thanks Uncle Smith. I found out where I was getting confused and such. While testing this, I was actually making a request to the page that I wanted to show, rather then what I wanted to see.

example:

http://www.mysite.com/article.php?aid=cat_dog

rather then making request to

http://www.mysite.com/cat_dog.php

I spent a totally of 15 hours on this and it was because my lack common sense. I was writing the rules right, but testing wrong. Thanks for all your help!

Ok but what about database optimization rules that prefers using a numeral id instead of a text one ??

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.