| | |||||
| ||||||||
| Programming PHP, Perl, Ruby on Rails, AJAX, HTML, XHTML, CSS, JavaScript, MySQL and any other coding topics. |
![]() |
| | LinkBack | Thread Tools |
| | THREAD STARTER #1 (permalink) |
| Account Closed Join Date: Dec 2005 Location: ../home/mysite
Posts: 3,566
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() | 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. |
| |
| | #2 (permalink) |
| Traveller Join Date: Mar 2007 Location: Yet another city
Posts: 1,419
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() | 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 |
| |
| | THREAD STARTER #3 (permalink) |
| Account Closed Join Date: Dec 2005 Location: ../home/mysite
Posts: 3,566
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() | 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.
|
| |
| | #4 (permalink) |
| Traveller Join Date: Mar 2007 Location: Yet another city
Posts: 1,419
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() | 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 |
| |
| | #6 (permalink) |
| Traveller Join Date: Mar 2007 Location: Yet another city
Posts: 1,419
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() | Sorry, I'm at work, can only reply when the boss is not looking!
__________________ NameCooler.com |
| |
| | #8 (permalink) |
| Buy my domains. Join Date: Feb 2006
Posts: 2,796
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() | Code: RewriteEngine on RewriteRule ^[_a-zA-Z0-9]*-[_a-zA-Z0-9]*-[_a-zA-Z0-9]*-([0-9]*)?\.html index.php?id=$1 Put that in your .htaccess. You'll just need to make sure you use 3 words, followed by the id. |
| |
| | #9 (permalink) |
| Traveller Join Date: Mar 2007 Location: Yet another city
Posts: 1,419
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() | 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 |
| |
| | THREAD STARTER #10 (permalink) |
| Account Closed Join Date: Dec 2005 Location: ../home/mysite
Posts: 3,566
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() | 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! |
| |
| | #11 (permalink) |
| Traveller Join Date: Mar 2007 Location: Yet another city
Posts: 1,419
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() | ^[_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 |
| |
| | #13 (permalink) |
| Traveller Join Date: Mar 2007 Location: Yet another city
Posts: 1,419
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() | 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 |
| |
| | THREAD STARTER #14 (permalink) |
| Account Closed Join Date: Dec 2005 Location: ../home/mysite
Posts: 3,566
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() | 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] 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.
|
| |