Jump to content

SEF URLs


amwd07

Recommended Posts

Hello I have finally got the spaces to replace with - in php

but although the page now links there seems to be no output here if I remove the - and put in %20

the page comes up fine it also work with using + instead of space

 

can someone please help with this MYSQL coding or maybe soemthing in htaccess needs to be defined?

 

this work for a hyperlink but when the can't find page

 

http://www.madeinshropshire.co.uk/demo/index.php?title=about+us (this works)

http://www.madeinshropshire.co.uk/demo/index.php?title=about%20us (this works)

http://www.madeinshropshire.co.uk/demo/index.php?title=about-us (this needs to work)

 

$title=mysql_result($result1,$i,"title");

$sef = stringForUrl($title);

example link <a href=index.php?title=$sef>$title</a>

 

<?php function stringForUrl($strIn) {

$strOut = $strIn;

$allowed = '/[^a-z0-9 ]/ims';

 

// only alphanum and spaces allowed

$strOut = preg_replace($allowed, '', $strOut);

 

// swap spaces for _

$strOut = str_replace(' ', '-', $strOut);

 

// make lower case for consistancy

$strOut = strtolower($strOut);

 

return $strOut;

}

 

$sef = stringForUrl($title);

?>

Link to comment
Share on other sites

Thank you for your reply but that did not work

here is my code below as you can see it is working here

 

http://www.madeinshropshire.co.uk/demo/index.php?title=about+us

but when I try to use about-us through the link created

<a href=index.php?title=$sef>$title</a> it shows the correct url but no output from the page

do I need something else to get this to work?

 

<?php function stringForUrl($strIn) {
$strOut = $strIn;
$allowed = '/[^a-z0-9 -]/ims';

// only alphanum and spaces allowed
$strOut = preg_replace($allowed, '', $strOut);

// swap spaces for _
$strOut = str_replace(' ', '-', $strOut);

// make lower case for consistancy
$strOut = strtolower($strOut);

return $strOut;
}

?>


$content_id=mysql_result($result1,$i,"content_id");
$title=mysql_result($result1,$i,"title");
$desc=mysql_result($result1,$i,"desc");
$sef = stringForUrl($title);

////////////////////////////////////////////////////////

$site_title = "Made In Shropshire Demo Site";
$page_title = "$title";
$main .= "<a href=index.php?title=$sef>$title</a><hr>$desc";

 

 

Link to comment
Share on other sites

 

change

$allowed = '/[^a-z0-9 ]/ims';

to

$allowed = '/[^a-z0-9 -+]/ims';

 

 

as a note you did say it worked for +

 

Link to comment
Share on other sites

I see what your saying but this only work for the link $strOut

don't i need to have something so the url remains the same but the page queries about%20us from the DB

 

%20 is th esame as the plus this is why this already works.

 

maybe this can't be done in PHP or do I need some kind of htaccess rule

all I want to do is take out those annoying spaces and replace them with ever hypen or underscore

shouln't be to difficult should it?

 

example of URL from another site

 

Craven%20Arms%20Hotel (Craven+Arms+Hotel) this would work but is no good to me

 

this would be much more friendly

craven-arms-hotel or (craven_arms_hotel)

 

Link to comment
Share on other sites

OK I will try and simplify this

 

the current url shows up the content id 1 from database about us

this is how it is written in the database and is also used for the menu on the left for dynamic updatable links

 

Now the link in index.php <a href=index.php?title=$sef>$title</a>

sef refers to $sef = stringForUrl($title); 

(title is coming from here)  $title=mysql_result($result1,$i,"title");

 

No when you click about us from the menu on the left notice the url is

http://www.madeinshropshire.co.uk/demo/index.php?title=about+us (this is without the function)

 

now if you click the title about us and not the navigation link you will notice the URL changes to

http://www.madeinshropshire.co.uk/demo/index.php?title=about-us (this is using the function)

 

this is axactly what I wanted to happen the function works the way it should but now the problem

is about us is not being found from the DB this is because there is a space in the name, I don't want to change anything in the database or the url I just need to have the same output as this url

http://www.madeinshropshire.co.uk/demo/index.php?title=about-us

 

once this is working I can create a HTACCESS rule to convert the new SEF URL to

http://www.madeinshropshire.co.uk/about-us/

 

 

 

Link to comment
Share on other sites

sorry still makes no sense, if you change the URL to one that doesn't work it.. it will not work!

you should be changing the title not the link the very fact your filtering output from the database and then trying to link back via that data confuses me..

 

sorry either i have failed to understand what you are trying to do or your logic is incorrect..

Link to comment
Share on other sites

 

yes this would work I can stip down the url in HTACCESS to read like this

http://www.madeinshropshire.co.uk/demo/about-us

 

but my question is how do I get the htaccess to ignore the title?

any if it does ignor ewill th epage still show with the contents?

 

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.