[advanced search]
 

Go Back   NamePros.com > Discussion > Web Design & Development > Programming

Programming PHP, Perl, Ruby on Rails, AJAX, HTML, XHTML, CSS, JavaScript, MySQL and any other coding topics.


Closed Thread
 
LinkBack Thread Tools
Old 05-17-2007, 05:19 AM   #1 (permalink)
Account Closed
 
JuggernautH's Avatar
 
Join Date: Dec 2005
Location: ../home/mysite
Posts: 3,566
37.00 NP$ (Donate)

JuggernautH has much to be proud ofJuggernautH has much to be proud ofJuggernautH has much to be proud ofJuggernautH has much to be proud ofJuggernautH has much to be proud ofJuggernautH has much to be proud ofJuggernautH has much to be proud ofJuggernautH has much to be proud ofJuggernautH has much to be proud ofJuggernautH has much to be proud of

Cancer Child Abuse
Help with MOD_REWRITE PLZ!

Hi, currently building something for a site i am going to relaunch
I want index.php?id=3 rewritten so it makes it show the name like this name-nextword-lastword_1.html and so on.

You get the point, how would i do that? If you need to see the code i use i can supply it to honest people.
JuggernautH is offline  
Old 05-17-2007, 05:49 AM   #2 (permalink)
Traveller
 
-NC-'s Avatar
 
Join Date: Mar 2007
Location: Yet another city
Posts: 1,392
614.57 NP$ (Donate)

-NC- has much to be proud of-NC- has much to be proud of-NC- has much to be proud of-NC- has much to be proud of-NC- has much to be proud of-NC- has much to be proud of-NC- has much to be proud of-NC- has much to be proud of-NC- has much to be proud of-NC- has much to be proud of

Animal Cruelty Animal Rescue Ethan Allen Fund Protect Our Planet
Do you have 3 = name-nextword-lastword stored anywhere e.g. a database?

Or is the name-nextword-lastword simply hardcoded in the href?

Here is an example to turn

/3/ into index.php?id=3

Options +FollowSymLinks
Options +Indexes
RewriteEngine On
RewriteBase /
RewriteCond %{SCRIPT_FILENAME} !-f
RewriteCond %{SCRIPT_FILENAME} !-d
RewriteRule ^/([^/]+)/?$ index.php?id=$1 [NC,L]

If the name-nextword-lastword is simply hardcoded in the href, you could do:

/3/name-nextword-lastword/

Options +FollowSymLinks
Options +Indexes
RewriteEngine On
RewriteBase /
RewriteCond %{SCRIPT_FILENAME} !-f
RewriteCond %{SCRIPT_FILENAME} !-d
RewriteRule ^/([^/]+)/([^/]+)/?$ index.php?id=$1 [NC,L]


disclaimer: I'm no mod_rewrite master
-NC- is offline  
Old 05-17-2007, 05:54 AM   #3 (permalink)
Account Closed
 
JuggernautH's Avatar
 
Join Date: Dec 2005
Location: ../home/mysite
Posts: 3,566
37.00 NP$ (Donate)

JuggernautH has much to be proud ofJuggernautH has much to be proud ofJuggernautH has much to be proud ofJuggernautH has much to be proud ofJuggernautH has much to be proud ofJuggernautH has much to be proud ofJuggernautH has much to be proud ofJuggernautH has much to be proud ofJuggernautH has much to be proud ofJuggernautH has much to be proud of

Cancer Child Abuse
Just got the titles in the db, basicly like this "Welcome to site" for example. Would this do the trick?
None of those apparently worked

Last edited by JuggernautH; 05-17-2007 at 05:57 AM.
JuggernautH is offline  
Old 05-17-2007, 06:23 AM   #4 (permalink)
Traveller
 
-NC-'s Avatar
 
Join Date: Mar 2007
Location: Yet another city
Posts: 1,392
614.57 NP$ (Donate)

-NC- has much to be proud of-NC- has much to be proud of-NC- has much to be proud of-NC- has much to be proud of-NC- has much to be proud of-NC- has much to be proud of-NC- has much to be proud of-NC- has much to be proud of-NC- has much to be proud of-NC- has much to be proud of

Animal Cruelty Animal Rescue Ethan Allen Fund Protect Our Planet
The good news:
You're in good shape if you've got the titles/id's in the DB!

The bad news:
I think you're going to need some additional php to:

get the title from the url
modify it so that it looks like the title in the db
query the db to get the ID

e.g.
url:
/name-nextword-lastword/

rewrite:
RewriteRule ^/([^/]+)/?$ index.php?name=$1 [NC,L]

index.php
(pseudo code)
$dbname = str_replace('-', ' ', $_GET['name']);

(replace the underscores with spaces)

select id from database where title = $dbname


Oh erm, just to clarify, your example url:
name-nextword-lastword_1.html

"1" isnt the ID is it?
-NC- is offline  
Old 05-17-2007, 06:34 AM   #5 (permalink)
Account Closed
 
JuggernautH's Avatar
 
Join Date: Dec 2005
Location: ../home/mysite
Posts: 3,566
37.00 NP$ (Donate)

JuggernautH has much to be proud ofJuggernautH has much to be proud ofJuggernautH has much to be proud ofJuggernautH has much to be proud ofJuggernautH has much to be proud ofJuggernautH has much to be proud ofJuggernautH has much to be proud ofJuggernautH has much to be proud ofJuggernautH has much to be proud ofJuggernautH has much to be proud of

Cancer Child Abuse
Hey, you got msn or something we can chat over? Could show you how the code looks like in that case, would be realy nice of you
JuggernautH is offline  
Old 05-17-2007, 07:45 AM   #6 (permalink)
Traveller
 
-NC-'s Avatar
 
Join Date: Mar 2007
Location: Yet another city
Posts: 1,392
614.57 NP$ (Donate)

-NC- has much to be proud of-NC- has much to be proud of-NC- has much to be proud of-NC- has much to be proud of-NC- has much to be proud of-NC- has much to be proud of-NC- has much to be proud of-NC- has much to be proud of-NC- has much to be proud of-NC- has much to be proud of

Animal Cruelty Animal Rescue Ethan Allen Fund Protect Our Planet
Sorry, I'm at work, can only reply when the boss is not looking!
-NC- is offline  
Old 05-17-2007, 08:34 AM   #7 (permalink)
Account Closed
 
JuggernautH's Avatar
 
Join Date: Dec 2005
Location: ../home/mysite
Posts: 3,566
37.00 NP$ (Donate)

JuggernautH has much to be proud ofJuggernautH has much to be proud ofJuggernautH has much to be proud ofJuggernautH has much to be proud ofJuggernautH has much to be proud ofJuggernautH has much to be proud ofJuggernautH has much to be proud ofJuggernautH has much to be proud ofJuggernautH has much to be proud ofJuggernautH has much to be proud of

Cancer Child Abuse
Hehe okay :P
JuggernautH is offline  
Old 05-17-2007, 12:56 PM   #8 (permalink)
Dan
Buy my domains.
 
Dan's Avatar
 
Join Date: Feb 2006
Posts: 2,801
56.00 NP$ (Donate)

Dan has a brilliant futureDan has a brilliant futureDan has a brilliant futureDan has a brilliant futureDan has a brilliant futureDan has a brilliant futureDan has a brilliant futureDan has a brilliant futureDan has a brilliant futureDan has a brilliant futureDan has a brilliant future

Autism Autism Autism Autism Autism Autism Autism
Code:
RewriteEngine on
RewriteRule ^[_a-zA-Z0-9]*-[_a-zA-Z0-9]*-[_a-zA-Z0-9]*-([0-9]*)?\.html index.php?id=$1
(site.com/something-hola-yay-3.html)

Put that in your .htaccess. You'll just need to make sure you use 3 words, followed by the id.
Dan is offline  
Old 05-17-2007, 03:46 PM   #9 (permalink)
Traveller
 
-NC-'s Avatar
 
Join Date: Mar 2007
Location: Yet another city
Posts: 1,392
614.57 NP$ (Donate)

-NC- has much to be proud of-NC- has much to be proud of-NC- has much to be proud of-NC- has much to be proud of-NC- has much to be proud of-NC- has much to be proud of-NC- has much to be proud of-NC- has much to be proud of-NC- has much to be proud of-NC- has much to be proud of

Animal Cruelty Animal Rescue Ethan Allen Fund Protect Our Planet
Yeah that should work great as long as that number at the end is the ID!
(I was wondering if I had overlooked the obvious there....)

Nice regexp skills Dan!

edit: just noticed your title in your postbit, love the subliminal advertising message!
-NC- is offline  
Old 05-17-2007, 04:01 PM   #10 (permalink)
Account Closed
 
JuggernautH's Avatar
 
Join Date: Dec 2005
Location: ../home/mysite
Posts: 3,566
37.00 NP$ (Donate)

JuggernautH has much to be proud ofJuggernautH has much to be proud ofJuggernautH has much to be proud ofJuggernautH has much to be proud ofJuggernautH has much to be proud ofJuggernautH has much to be proud ofJuggernautH has much to be proud ofJuggernautH has much to be proud ofJuggernautH has much to be proud ofJuggernautH has much to be proud of

Cancer Child Abuse
Alright thanks Dan, will test that later. How would i go if i wanted to do it like this "index.php?id=1" to "review_1.html" for example? The review word will be same for all of the pages.

Thanks for any answers!
JuggernautH is offline  
Old 05-17-2007, 04:12 PM   #11 (permalink)
Traveller
 
-NC-'s Avatar
 
Join Date: Mar 2007
Location: Yet another city
Posts: 1,392
614.57 NP$ (Donate)

-NC- has much to be proud of-NC- has much to be proud of-NC- has much to be proud of-NC- has much to be proud of-NC- has much to be proud of-NC- has much to be proud of-NC- has much to be proud of-NC- has much to be proud of-NC- has much to be proud of-NC- has much to be proud of

Animal Cruelty Animal Rescue Ethan Allen Fund Protect Our Planet
^[_a-zA-Z0-9]*-[_a-zA-Z0-9]*-[_a-zA-Z0-9]*-([0-9]*)?\.html

Actually, there is an underscore at the end, so should it be:

^[_a-zA-Z0-9]*-[_a-zA-Z0-9]*-[_a-zA-Z0-9]*_([0-9]*)?\.html

or if underscore is a special char in .htaccess, it would be:

^[_a-zA-Z0-9]*-[_a-zA-Z0-9]*-[_a-zA-Z0-9]*\_([0-9]*)?\.html


JuggernautH, it should work fine as long as there is only ever 3 words including review. Are you asking what if you have any number of hypen delimited words before the review_{id}.html?
-NC- is offline  
Old 05-17-2007, 04:15 PM   #12 (permalink)
Account Closed
 
JuggernautH's Avatar
 
Join Date: Dec 2005
Location: ../home/mysite
Posts: 3,566
37.00 NP$ (Donate)

JuggernautH has much to be proud ofJuggernautH has much to be proud ofJuggernautH has much to be proud ofJuggernautH has much to be proud ofJuggernautH has much to be proud ofJuggernautH has much to be proud ofJuggernautH has much to be proud ofJuggernautH has much to be proud ofJuggernautH has much to be proud ofJuggernautH has much to be proud of

Cancer Child Abuse
Yes i would need to know that as well what would i put in the htaccess if i wanted to list review-{id}.html for example
JuggernautH is offline  
Old 05-17-2007, 04:26 PM   #13 (permalink)
Traveller
 
-NC-'s Avatar
 
Join Date: Mar 2007
Location: Yet another city
Posts: 1,392
614.57 NP$ (Donate)

-NC- has much to be proud of-NC- has much to be proud of-NC- has much to be proud of-NC- has much to be proud of-NC- has much to be proud of-NC- has much to be proud of-NC- has much to be proud of-NC- has much to be proud of-NC- has much to be proud of-NC- has much to be proud of

Animal Cruelty Animal Rescue Ethan Allen Fund Protect Our Planet
hmm, should be easy actually!

I guess Dan will be able to correct me if I'm wrong, but in that case, all we care about is the _{number}.html

So, here goes:
^[\-_a-zA-Z0-9]*\_([0-9]*)?\.html

There's definitely a better regex than that though, here's another attempt:

^/([^/\_]+)\_([0-9]*)?\.html

Guess I should actually fire up apache and test!
-NC- is offline  
Old 05-17-2007, 04:33 PM   #14 (permalink)
Account Closed
 
JuggernautH's Avatar
 
Join Date: Dec 2005
Location: ../home/mysite
Posts: 3,566
37.00 NP$ (Donate)

JuggernautH has much to be proud ofJuggernautH has much to be proud ofJuggernautH has much to be proud ofJuggernautH has much to be proud ofJuggernautH has much to be proud ofJuggernautH has much to be proud ofJuggernautH has much to be proud ofJuggernautH has much to be proud ofJuggernautH has much to be proud ofJuggernautH has much to be proud of

Cancer Child Abuse
Could you write me up the whole code for it? Kind of novice on this stuff myself :P

Tryed for a while myself and i managed to get it working Thanks for all help!

Code:
RewriteRule ^review_([0-9]+).html reviews.php?id=$1 [L,NC]
That's what i used!

Dan & RCRiver:
Go to www.hideurl.info/reviews.html to check the script live
If you want i can review one each of your sites for free and put it there

Last edited by JuggernautH; 05-17-2007 at 05:00 PM.
JuggernautH is offline  
Closed Thread


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Site Sponsors
Advertise your business at NamePros

All times are GMT -7. The time now is 03:28 PM.


Powered by: vBulletin® Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.3.0
Template-Modifications by TMS
vBCredits v1.4 Copyright ©2007 - 2008, PixelFX Studios

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85