add articleheadline to the rewrite URL - is it possible?

Get help with installation and running phpwcms here. Please do not post bug reports or feature requests here.
Post Reply
User avatar
marcus@localhorst
Posts: 815
Joined: Fri 28. May 2004, 11:31
Location: localhorst
Contact:

add articleheadline to the rewrite URL - is it possible?

Post by marcus@localhorst »

holla,

is it possible to rewrite the url from 1.3.0.0.0.phtml to
this-is-my-article-headline-1.3.0.0.0.phtml ?

what must be change? only the .htaccess?

it's important!
thanks
marcus
Ben
Posts: 558
Joined: Wed 14. Jan 2004, 08:05
Location: Atlanta
Contact:

Post by Ben »

Marcus,
You may already know this, but if you fill in the alias for each page, the urls become http://www.domain.com/your_alias.phtml. It must be manually determined for each page and is not automatically assigned by the article title, though.
User avatar
marcus@localhorst
Posts: 815
Joined: Fri 28. May 2004, 11:31
Location: localhorst
Contact:

Post by marcus@localhorst »

yeah, thats the alias for each category - but i like to use it for every article :?
User avatar
marcus@localhorst
Posts: 815
Joined: Fri 28. May 2004, 11:31
Location: localhorst
Contact:

Post by marcus@localhorst »

no idea here? :?
User avatar
Oliver Georgi
Site Admin
Posts: 9919
Joined: Fri 3. Oct 2003, 22:22
Contact:

Post by Oliver Georgi »

not possible by default.

Oliver
Oliver Georgi | phpwcms Developer | GitHub | LinkedIn | Систрон
User avatar
marcus@localhorst
Posts: 815
Joined: Fri 28. May 2004, 11:31
Location: localhorst
Contact:

Post by marcus@localhorst »

i thought it is only needed to change the rewrite rule in .htaccess and searching for the function (i didn't found it yet) which convert the querystring into filename.
then query to each id the headline, if possible and add it to the URL.

it should not very complicated? (i should try it, but have not very much time...). any suggestion to begin with that?

greetings marcus
User avatar
marcus@localhorst
Posts: 815
Joined: Fri 28. May 2004, 11:31
Location: localhorst
Contact:

Post by marcus@localhorst »

Hi,
Is there a mod_rewrite guru???

I've modified the function that turns all urls in PHPWCMS in static.phtml pages to get the following url:

1.1.0.0.0.0-this-is-the-article-headline.phtml

that part works, only the htaccess makes me crazy and my provider nervous.

i tried this in different variations (with [L] etc) but everytime it crashes the server.

Code: Select all

# This will rewrite 0.0.0.0.0.0.phtml => index.php?id=0.0.0.0.0.0
RewriteRule ^([0-9]+)\.([0-9]+)\.([0-9]+)\.([0-9]+)\.([0-9]+)\.([0-9]+)[color=orange][b]-(.+)[/b][/color]\.phtml$ index.php?id=$1,$2,$3,$4,$5,$6

# This will rewrite mypage.phtml => index.php?mypage
RewriteRule ^(.+)\.phtml$ index.php?$1
I don't want to try this out, if I freeze the server.
so I hope to find someone, that have an idea?!

it seems, that the 2. rule grab the first rule, too?!
any idea?
please - i need that enhancement for a customer. he believe that such urls are better for the SEO ranking. as far as i know that is not really relevant. the urls are easier to read, that would be a pro...

best marcus
User avatar
marcus@localhorst
Posts: 815
Joined: Fri 28. May 2004, 11:31
Location: localhorst
Contact:

[dirtyhack] add articleheadline to the rewrite URL

Post by marcus@localhorst »

i found an easy solution to add article headlines, to the url.
I know it's irrelevant for search engines to have a 1.3.0.0.0.phtml or a 1.3.0.0.0@this-is-my-article-headline.phtml url, but a customer want this. so I try it...

Attention, this is a quick and dirty hack and it works for me at the moment...

open front.func.inc.php and searching for
(ca. on line 2080)
// REWRITE - PATCHED FOR 04/04 // jan212
function url_search($query)

Code: Select all

// REWRITE - PATCHED FOR 04/04 // jan212
function url_search($query) { 
	if ( substr($query,0,4) == '?id=') { 
		$noid = substr($query, 4); 
		
//---------------------------------------------------- 
// first find the articleid in $noid 
$aktion = explode(',', $noid); 
$aktion = array_map('intval', $aktion); 
$article_id = $aktion[1];   


// rewrite articleurl hack by marcus@localhorst 
$dbcon = mysql_pconnect($GLOBALS["phpwcms"]["db_host"], $GLOBALS["phpwcms"]["db_user"], $GLOBALS["phpwcms"]["db_pass"]);
mysql_select_db($GLOBALS["phpwcms"]["db_table"],$dbcon);
         
$sql  = "SELECT article_id, article_title, article_cid, UNIX_TIMESTAMP(article_tstamp) AS article_date "; 
$sql .= "FROM ".DB_PREPEND."phpwcms_article WHERE article_id =".$article_id; 

$result = mysql_query($sql,$dbcon);
echo mysql_error();

while ($row = mysql_fetch_row($result)) { 
  $article_title = $row[1]; 
  $article_title = strtolower($article_title);
  $article_title = trim($article_title);
  $article_title = str_replace(' ', '-', $article_title);
  $article_title = str_replace(':', '-', $article_title);
  $article_title = str_replace('"', '', $article_title);
  $article_title = str_replace('?', '', $article_title);
  $article_title = str_replace('!', '', $article_title);
  $article_title = str_replace('=', '', $article_title);
  $article_title = str_replace('\'', '', $article_title);
  $article_title = str_replace('/', '-', $article_title);
  $article_title = str_replace('ä', 'ae', $article_title);
  $article_title = str_replace('ö', 'oe', $article_title);
  $article_title = str_replace('ü', 'ue', $article_title);

  $noid = str_replace(',', '.', $noid).'@'.$article_title;    
}       
mysql_free_result($result);   
// end rewrite ------------------------------- 
		
		//$file = str_replace(',', '.', $noid).'.html'; 
		//$file = str_replace(',', '.', $noid).'.phtml'; 
		$file = $noid.'.phtml'; 
	} else { 
		$noid = substr($query,1); 
		//$file = str_replace(',', '.', $noid).'.html'; 
		$file = str_replace(',', '.', $noid).'.phtml';
		//$file = $noid.'.phtml'; 
	} 
	$link = ' href="'.$file.'"'; 
	return($link); 
}
open the .htaccess and search for

# Default ReWrite settings for phpwcms
Replace the default rewrite rule wit this:

Code: Select all

RewriteRule ^([0-9]+)\.([0-9]+)\.([0-9]+)\.([0-9]+)\.([0-9]+)\.([0-9]+)@(.*)\.phtml$ index.php?id=$1,$2,$3,$4,$5,$6
tell me what you think. I'm not a real PHP Programmer/Fan - so maybe you could do it better?!
(the url replacement could be a function and as i remember right, a similar function is available (which converts the cat aliases)

greetings marcus[/code]
User avatar
jsw_nz
Posts: 907
Joined: Fri 2. Apr 2004, 02:42
Location: New Zealand

Post by jsw_nz »

Hi Marcus,

Your code works great. Tested it on my 'localhorst' :D

A couple of questions - one directly related to this and another of a more general nature.

First Question:
I noticed you put an @ symbol within the concat of url_search function. Not sure about this, but would this be the suggested character? I am so used to using '_' - so to me its kinder on the eyes/mind - but there may be a reason for this (your @) - anyway this works great - but not sure if this actually improves SEO - although as you mentioned it is easier to read/understand.

Second Question:

I am using artilcle templates - and as far as my code is working - the {ARTICLELINK} tag is returned non-rewrittin link. Just discovered this minutes ago...wnated to ask if you have had similar problems - maybe just me - since I am using lookup script to determine number of comments to a given article -

Second Question SOLVED:
Had to apply double quotes around "{ARTICLELINK}"
Here is the thread:
http://www.phpwcms.de/forum/viewtopic.php?p=69008#69008

Anyway - guessing there is no harm in you very smart approach - am bookmarking this page. THANKS

:D :D
miershpedankl
Posts: 39
Joined: Wed 8. Mar 2006, 13:19
Location: East Coast, USA
Contact:

Post by miershpedankl »

This dicussion has been helpful to read. I have succesfully rewritten the URL, but now I get an error that the page does not exist and, therefore, I cannot access it. Can you help me solve this problem??

Thanks,
Miershpedankl
If you don't let ANYTHING happen to someone, then NOTHING will happen to them.
Post Reply