TalkPHP
 
 
Account Login
Latest Articles
» The basic usage of PHPTAL, a XML/XHTML template library for PHP
» Vulnerable methods and the areas they are commonly trusted in.
» Simple way to protect a form from bot
» The Basics On: How Session Stealing Works
» How to keep your forms from double posting data
IRC Channel
IRC Speech Bubble Join the friendly bunch on IRC...
(#TalkPHP on Freenode)

...Also available via a web interface.

See this thread for information on the TalkPHP Free Hugs Initiative™. Subject to availability.
Associates
Associates
CSS Tutorials
Reply
 
LinkBack Thread Tools Search this Thread Display Modes
Old 04-05-2010, 04:49 PM   #1 (permalink)
The Visitor
 
Join Date: Apr 2010
Posts: 2
Thanks: 0
MicroHellas is on a distinguished road
Default mod_rewrite for page title

Hello,

Maybe not beginner in PHP but totally novice when it comes to Apache files. So, I'll appreciate your patience. The problem that I want to resolve is:

With PHP functions and parametters, I'm able to pass to the page as title eg a Classified's title. The problem comes when I want to make the url:
Code:
classifieds.php?do=viewitem&itemid=xxx&title=xxx
to look like:
Code:
classifieds/title_here.html
I've tried many possible ways following tutorials but I was unable to make it work My last try is:
Code:
<IfModule mod_rewrite.c>
	RewriteEngine on
	RewriteRule ^classifieds/([0-9]+)-[^\/]+\.html$ classifieds.php?do=viewitem&itemid=$1 [L]
</IfModule>
You can check my page at:
http://www.microdemosite.com/dev4/cl...item&itemid=53
(even if I need to change a bit the code to replace spaces with underscores).

Thank you in advance
Maria
MicroHellas is offline  
Reply With Quote
Old 04-05-2010, 05:05 PM   #2 (permalink)
is cute and cuddly
 
delayedinsanity's Avatar
 
Join Date: Mar 2008
Location: Vegas, Baby
Posts: 963
Thanks: 31
delayedinsanity is on a distinguished road
Default

It looks like you're attempting to create the following structure, correct me if I'm wrong;

/classifieds/{$itemid}_{$title}.html

The following should do the trick:

Code:
RewriteEngine On
RewriteRule ^classifieds/([0-9]+)_([^.]+)\.html$ classifieds.php?do=viewitem&itemid=$1&title=$2 [L]
The first capture looks for a set of numbers, which you have accomplished on your own. The second capture after the underscore is looking for any group of characters up until it finds a period. Since it's enclosed in a character range, you don't have to escape it as a control character. Outside of the range it does need to be escaped, as shown here.

Hth

Edit: This allows a lot of freedom in how the title is presented. If you want to ensure that it's only alphabetical, or alphanumerical, replace [^.] with [A-Za-z] or [A-Za-z0-9] or finally [a-z] with NC added at the end [NC,L]
delayedinsanity is offline  
Reply With Quote
Old 04-05-2010, 05:25 PM   #3 (permalink)
The Visitor
 
Join Date: Apr 2010
Posts: 2
Thanks: 0
MicroHellas is on a distinguished road
Default

Thank you for your help, but unfortunatelly it dosen't works.
http://www.microdemosite.com/dev4/cl...item&itemid=15

If you visit the page you'll see the title to be as I want to be in the URL.

Maria
MicroHellas is offline  
Reply With Quote
Old 04-05-2010, 06:45 PM   #4 (permalink)
is cute and cuddly
 
delayedinsanity's Avatar
 
Join Date: Mar 2008
Location: Vegas, Baby
Posts: 963
Thanks: 31
delayedinsanity is on a distinguished road
Default

Works fine for me, I tested it locally. If you just need itemid and not title like the url you posted suggests, then you might try this:

Code:
RewriteRule ^classifieds/([0-9]+)_[^.]+\.html$ classifieds.php?do=viewitem&itemid=$1 [L]
That simply passes the itemid, and lets you add anything you want after it.
delayedinsanity is offline  
Reply With Quote
Reply



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

Advanced Search
Display Modes

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

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

Similar Threads
Thread Thread Starter Forum Replies Last Post
If duplicate title, add rand else, do nothing?? marxx General 3 02-17-2010 10:12 PM
Fetch Favicon and page title Sirupsen General 6 06-20-2009 05:48 PM
Img Title Embeded on Image? buildakicker General 3 01-08-2009 01:05 AM
[url] tag automatically grabs site title Runar Feedback 7 11-11-2008 03:29 PM
mod rewrite - how to get title in url? Sam Granger Absolute Beginners 5 10-10-2007 02:58 PM


All times are GMT. The time now is 03:10 PM.

 
     

Powered by vBulletin® Version 3.6.8
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.1.0
Inactive Reminders By Icora Web Design