Dear all
i read some online tutorial and i want to do seo my url but it not working any idea for it? my slug code below
<?php
setlocale(LC_ALL, 'en_US.UTF8');
function slug_url($str) {
$clean = iconv('UTF-8', 'ASCII//TRANSLIT', $str);
$clean = preg_replace("/[^a-zA-Z0-9\\/_| -]/", '', $clean);
$clean = strtolower(trim($clean, '-'));
$clean = preg_replace("/[\\/_| -]+/", '-', $clean);
return $clean;
}
?>
The requested URL /articledetailphpph-sc-art-titleenvolkswagen-bentley-to-make-an-suv was not found on this server.
Additionally, a 404 Not Found error was encountered while trying to use an ErrorDocument to handle the request.
can not find the information so how to sold this problem?
Best regards,
Heng
Hi,
If your original URL is /articledetail.php?ph_sc_art_titleen=volkswagen-bentley-to-make-an-suv
then I’m guessing that you actually want your friendly URL to be /articles/volkswagen-bentley-to-make-an-suv
or maybe even /volkswagen-bentley-to-make-an-suv
?
In any case, what you need to do is change your .htaccess file (or create one, if it doesn’t exist) in your web root directory, and do something like this:
<IfModule mod_rewrite.c>
# Turn on URL rewriting
RewriteEngine On
# Installation directory
RewriteBase /
# Allow any files or directories that exist to be displayed directly
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
# Rewrite article URLs to articledetail.php
RewriteRule ^articles/(.*)$ articledetail.php?ph_sc_art_titleen=$1
</IfModule>
hengwebdeveloper, please can you post here and not by private message. If my suggestion isn’t working for you, can you describe what you’re doing and what errors you’re getting, and then I (or others) can help you.
fretburner, i was copy and past your code into my .htaccess file it not working do i need to use slug and .htaccess both?
Yes, you need both. Your code generates the friendly URL, and the rewrite rules in .htaccess translate those URLs into instructions to the server about which file to load.
When you say it’s not working, are you getting a 404 not found error or something?
yeah it getting error because the url need articledetail.php to execute the code does my slug it right? or where the wrong part?
OK, so I’ve got a couple things you can try.
Edit your .htaccess file and try adding this line at the top (above the <IfModule mod_rewrite.c>
line):
Options -MultiViews
If that doesn’t work, you could also try editing this line:
RewriteRule ^articles/(.*)$ /articledetail.php?ph_sc_art_titleen=$1
Notice that I’ve added a / before articledetail.php - this seems to make a difference on some servers.
no it still not working because it need 1 file to execute code
I thought you already had a file called articledetail.php… but now you’re saying that you don’t? In that case, just start with something like this to check that it’s working:
<?php
var_dump($_GET);
Then you can try going to http://www.sabaychet.com/articles/volkswagen-bentley-to-make-an-suv
or whatever your URL is.