You will either need to keep the id in the name of the url, such as /add-your-company-89 or you will need to be able to make coding changes to your system. As you would have to hit your database to determine /add-your-company is to be served the same information as artid=89.
The problem lies in the fact that your scripts today require an id. When given add-your-company, there isn’t an id provided so your scripts as they exist today won’t be able to serve the page being asked for.
Please read the sticky posts OR the link in my signature as the redirections are almost trivial - IF UNIQUE. View http://wilderness-wally.com for an example of how it’s done. If you still have questions (like the acceptable character set), come on back and ask.
I have no problem to keep an id within my url. Can you point me to some solution? I will soon end with bumping my head against the wall with this problem.
If you ever want to do categories in the same fashion as articles (example: mydomain.com/temporary/42-category-name/), then we need to tweak the rules, as both would expect to only receive one section and can’t be differentiated accordingly (example: mydomain.com/temporary/42-article-name/ looks the same as mydomain/com/temporary/42-category-name/ – we would need to make them look different).
@cpradio; that looks good! One thing though, RewriteCond’s only apply to the next RewriteRule following it. And since the RewriteCond’s should apply to both rules you need to repeat them for the second rule, like so:
First of all thanks to all of you who spent some of your time to answer my question. Especially to the people who write this code for me. Now…
I guess that many of you will rolling on the floor from laughing while reading my question…but…how on earth my htaccess file will know what is my article name when the id is for example 89??? Ok, I have the .htaccess file, should I just upload it on the server and it will work???
NO ROFL around here! Members only ask questions when they’re in need of help.
You are providing the catid, productid and artid via the query strings you’re appending. mod_rewrite has been instructed to ignore the name/title/description/whatever the other atom contains but that will be available to article.php via the db query.
FYI, except for the symbolic link test, your code looks much like WordPress’s mod_rewrite code. Within WP’s admin, there is a switch which tells WP to use either the id of the record or the title (for “pretty URIs”). It’s a nice feature that WP added at least a year ago.
Not sure exactly if this is the answer you are seeking, but you will still need to update your URLs in your website to use a “pretty” url (.htaccess can’t do that part for you), so where you have URLs like articles.php?artid=89, you will replace that link with /89-article-title-here/
As dklynn, stated, the rewrite rule specifically looks for the number in your URL ( example: /89-article-title-here/; anything not bold is ignored ), it then takes that 89, and tells apache, the request really wants what is stored at articles.php?artid=89 (notice the 89 from your pretty article gets put as the value of artid).
Products works similarly, the only difference is it looks for 2 numbers (a product id and a category id) instead of just one number.
Once again, thanks to all of you that find time to answer my questions.
Can you give me an example how can I do that? Should I create separate php file which will do this job? Can you write couple lines of code as an example?
Are you using any kind of CMS or software? Can you provide a link to the website? Without seeing it, I really can’t offer a way to update your existing links into the “pretty” links.