NamePros
Welcome, Guest! Ready to make a name for yourself in the domain business? We welcome both the hobbyist and professional domainer to join the discussion as part of the NamePros community.

Click here to create your profile to start earning reputation for posting, and trader ratings for buying & selling in our free e-marketplace. Build your trader rating with each successful sale. Our system has tracked over 100,000 sales and counting!
FAQ & TOS Register Search Today's Posts Mark Forums Read

Go Back   NamePros.com > Website Development Discussion Forums > Programming
Reload this Page Help with MOD_REWRITE PLZ!

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

Advanced Search


Closed Thread
 
LinkBack Thread Tools
Old 05-17-2007, 06:19 AM THREAD STARTER               #1 (permalink)
Account Closed
 
JuggernautH's Avatar
Join Date: Dec 2005
Location: ../home/mysite
Posts: 3,566
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, 06:49 AM   #2 (permalink)
Traveller
 
-NC-'s Avatar
Join Date: Mar 2007
Location: Yet another city
Posts: 1,419
-NC- has a brilliant future-NC- has a brilliant future-NC- has a brilliant future-NC- has a brilliant future-NC- has a brilliant future-NC- has a brilliant future-NC- has a brilliant future-NC- has a brilliant future-NC- has a brilliant future-NC- has a brilliant future-NC- has a brilliant future
 


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
????: NamePros.com http://www.namepros.com/programming/328878-help-with-mod_rewrite-plz.html

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
__________________
NameCooler.com
-NC- is offline  
Old 05-17-2007, 06:54 AM THREAD STARTER               #3 (permalink)
Account Closed
 
JuggernautH's Avatar
Join Date: Dec 2005
Location: ../home/mysite
Posts: 3,566
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 06:57 AM.
JuggernautH is offline  
Old 05-17-2007, 07:23 AM   #4 (permalink)
Traveller
 
-NC-'s Avatar
Join Date: Mar 2007
Location: Yet another city
Posts: 1,419
-NC- has a brilliant future-NC- has a brilliant future-NC- has a brilliant future-NC- has a brilliant future-NC- has a brilliant future-NC- has a brilliant future-NC- has a brilliant future-NC- has a brilliant future-NC- has a brilliant future-NC- has a brilliant future-NC- has a brilliant future
 


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]
????: NamePros.com http://www.namepros.com/showthread.php?t=328878

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?
__________________
NameCooler.com
-NC- is offline  
Old 05-17-2007, 07:34 AM THREAD STARTER               #5 (permalink)
Account Closed
 
JuggernautH's Avatar
Join Date: Dec 2005
Location: ../home/mysite
Posts: 3,566
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, 08:45 AM   #6 (permalink)
Traveller
 
-NC-'s Avatar
Join Date: Mar 2007
Location: Yet another city
Posts: 1,419
-NC- has a brilliant future-NC- has a brilliant future-NC- has a brilliant future-NC- has a brilliant future-NC- has a brilliant future-NC- has a brilliant future-NC- has a brilliant future-NC- has a brilliant future-NC- has a brilliant future-NC- has a brilliant future-NC- has a brilliant future
 


Animal Cruelty Animal Rescue Ethan Allen Fund Protect Our Planet
Sorry, I'm at work, can only reply when the boss is not looking!
__________________
NameCooler.com
-NC- is offline  
Old 05-17-2007, 09:34 AM THREAD STARTER               #7 (permalink)
Account Closed
 
JuggernautH's Avatar
Join Date: Dec 2005
Location: ../home/mysite
Posts: 3,566
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
JuggernautH is offline  
Old 05-17-2007, 01:56 PM   #8 (permalink)
Dan
Buy my domains.
 
Dan's Avatar
Join Date: Feb 2006
Posts: 2,796
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, 04:46 PM   #9 (permalink)
Traveller
 
-NC-'s Avatar
Join Date: Mar 2007
Location: Yet another city
Posts: 1,419
-NC- has a brilliant future-NC- has a brilliant future-NC- has a brilliant future-NC- has a brilliant future-NC- has a brilliant future-NC- has a brilliant future-NC- has a brilliant future-NC- has a brilliant future-NC- has a brilliant future-NC- has a brilliant future-NC- has a brilliant future
 


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!
__________________
NameCooler.com
-NC- is offline  
Old 05-17-2007, 05:01 PM THREAD STARTER               #10 (permalink)
Account Closed
 
JuggernautH's Avatar
Join Date: Dec 2005
Location: ../home/mysite
Posts: 3,566
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, 05:12 PM   #11 (permalink)
Traveller
 
-NC-'s Avatar
Join Date: Mar 2007
Location: Yet another city
Posts: 1,419
-NC- has a brilliant future-NC- has a brilliant future-NC- has a brilliant future-NC- has a brilliant future-NC- has a brilliant future-NC- has a brilliant future-NC- has a brilliant future-NC- has a brilliant future-NC- has a brilliant future-NC- has a brilliant future-NC- has a brilliant future
 


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?
__________________
NameCooler.com
-NC- is offline  
Old 05-17-2007, 05:15 PM THREAD STARTER               #12 (permalink)
Account Closed
 
JuggernautH's Avatar
Join Date: Dec 2005
Location: ../home/mysite
Posts: 3,566
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, 05:26 PM   #13 (permalink)
Traveller
 
-NC-'s Avatar
Join Date: Mar 2007
Location: Yet another city
Posts: 1,419
-NC- has a brilliant future-NC- has a brilliant future-NC- has a brilliant future-NC- has a brilliant future-NC- has a brilliant future-NC- has a brilliant future-NC- has a brilliant future-NC- has a brilliant future-NC- has a brilliant future-NC- has a brilliant future-NC- has a brilliant future
 


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!
__________________
NameCooler.com
-NC- is offline  
Old 05-17-2007, 05:33 PM THREAD STARTER               #14 (permalink)
Account Closed
 
JuggernautH's Avatar
Join Date: Dec 2005
Location: ../home/mysite
Posts: 3,566
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

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
????: NamePros.com http://www.namepros.com/showthread.php?t=328878
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 06:00 PM.
JuggernautH is offline  
Closed Thread


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


Liquid Web Smart Servers  
All times are GMT -7. The time now is 02:08 AM.

Managed Web Hosting by Liquid Web
Domain name forum recommended by Domaining.com Powered by: vBulletin® Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.6.0 Ad Management plugin by RedTyger