Removing ID from url

Discuss practical ways rearrange URLs using mod_rewrite.

Removing ID from url

Postby asundrus » Mon Mar 23, 2009 4:40 pm

I've got a site, build somewhat as a blog, and been trying to figure out how to remove the ID part from the url, I spent alot of time googling, and searching on this site too, but i'm utterly lost.

My url's looks like this:
Code: Select all
http://mysite.net/id=103&title;a_nice_blog_title

and what i'd like to do, is have it look like:
Code: Select all
http://mysite.net/a_nice_blog_title

My site is not hosted by me, therefor I have no access to any apache parts, which I read something about could make my wish possible.

I hope you can help me, or guide me in the right direction.

btw. this is my .htaccess entry:
Code: Select all
RewriteRule ^id=([^/]*)$ /?site=news&id=$1 [L]


And i'm still kinda new at this, so please bare with me, if I made any errors in this post.
asundrus
 
Posts: 3
Joined: Mon Mar 23, 2009 8:17 am

Postby scribzy » Mon Mar 23, 2009 8:29 pm

is the original url

http://mysite.net/?site=news&id=103&tit ... blog_title ?
:-?

(not with title;a_nice_blog_title) ?
scribzy
 
Posts: 5
Joined: Mon Mar 23, 2009 11:44 am

Postby richardk » Tue Mar 24, 2009 2:32 pm

FAQ: How to change a numeric ID into a name/title. The writing of an intermediate script or editing your script seems to be your options.
richardk
 
Posts: 8800
Joined: Wed Dec 21, 2005 7:50 am

Postby asundrus » Thu Mar 26, 2009 10:16 am

scribzy wrote:is the original url

http://mysite.net/?site=news&id=103&tit ... blog_title ?
:-?

(not with title;a_nice_blog_title) ?

Actually the original url would be:
http://mysite.net/?site=news&id=103
and this is without any .htaccess, the part with the title
is something I myself made in the script, by moving stuff around

From my functions.php the untouched part:
Code: Select all
<b><a href='?site=news&id=$news[id]' title='$news[title]'>$news[title]</a>


and here my own custom:
Code: Select all
<b><a href="id=$news[id]&amp;title;$newstitle">$news[title]</a></b>

which gives:
http://mysite.net/id=103&title;a_nice_blog_title

with this .htaccess:
RewriteRule ^id=([^/]*)$ /?site=news&id=$1 [L]

And I did look at viewtopic.php?p=11041#11041
but as couldn't find a solution.
asundrus
 
Posts: 3
Joined: Mon Mar 23, 2009 8:17 am

Postby richardk » Thu Mar 26, 2009 10:27 am

For /id=103&title;a_nice_blog_title to /?site=news&id=103
Code: Select all
Options +FollowSymLinks

RewriteEngine On

RewriteRule ^id=([0-9]+)&title;.+$ /?site=news&id=$1 [QSA,L]
richardk
 
Posts: 8800
Joined: Wed Dec 21, 2005 7:50 am

Postby asundrus » Thu Mar 26, 2009 10:47 am

richardk wrote:For /id=103&title;a_nice_blog_title to /?site=news&id=103
Code: Select all
Options +FollowSymLinks

RewriteEngine On

RewriteRule ^id=([0-9]+)&title;.+$ /?site=news&id=$1 [QSA,L]


Thanks for the reply, but how could I make it so that:

Code: Select all
id=103&title;

is not showen in the url? and sorry if im being thick headed
but i'm really trying to understand this.
asundrus
 
Posts: 3
Joined: Mon Mar 23, 2009 8:17 am

Postby richardk » Fri Mar 27, 2009 1:44 am

As the FAQ says, if you have access to the httpd.conf file you could use a RewriteMap. It is a text file or program that would change the title into the ID.

Or you will need to change the PHP (either by changing the original script or writing an intermediary script) so that it uses the title instead of the ID. Mod_rewrite would then only send the title to the script.
Code: Select all
Options +FollowSymLinks

RewriteEngine On

RewriteCond %{SCRIPT_FILENAME} !-f
RewriteCond %{SCRIPT_FILENAME} !-d
RewriteRule ^(.*[^/])/?$ /?site=news&THE_TITLE=$1 [QSA,L]
richardk
 
Posts: 8800
Joined: Wed Dec 21, 2005 7:50 am


Return to Friendly URLs with Mod_Rewrite

Who is online

Users browsing this forum: No registered users and 33 guests

cron