I am having my website and whenever I add a new page into it, it creates an url with random id number which I don't want. I would like to use the page/product
name as my URL, so what currently I am having is:
Current: http://www.abcdex.in/deal/d29e96cfd623a83f37f1bc12b4465131
Desired: http://www.abcdex.in/deal/Product-Name
I have gone through with my .htaccess
file and it shows at the bottom the following code:
RewriteEngine On
Options -Indexes
RewriteCond %{HTTP_HOST} !^www\.
RewriteRule ^(.*)$ http://www.%{HTTP_HOST}/$1 [R=301,L]
RewriteCond $1 !^(index\.php|assets|forum|robots\.txt|canvas\.xml)
RewriteRule ^(.*)$ index.php?/$1 [L]
Could anyone help me out because It is creating a lot of mess and I am loosing my site rank because of this?
Thank you in advance!
learn from this example and apply in your .htaccess Example
AddDefaultCharset utf-8
Options +FollowSymlinks -Indexes
RewriteEngine on
RewriteBase /living/
# skip all files and directories from rewrite rules below
#RewriteCond %{REQUEST_FILENAME} -d [OR]
#RewriteCond %{REQUEST_FILENAME} -f
#RewriteRule ^ - [L]
#RewriteRule ^authors/([^/]*)\.html$ main.php?authchar=$1 [QSA,L]
your .htaccess will be something like this your filenames
AddDefaultCharset utf-8
Options +FollowSymlinks -Indexes
RewriteEngine on
RewriteBase /
# skip all files and directories from rewrite rules below
#RewriteCond %{REQUEST_FILENAME} -d [OR]
#RewriteCond %{REQUEST_FILENAME} -f
#RewriteRule ^ - [L]
#RewriteRule ^deal/([^/]*)\.html$ yourscript.php?d29e96cfd623a83f37f1bc12b4465131=$1 [QSA,L]
You can try do all of this in htaccess, but I like to solve these issues in PHP
On all of your pages with URLs similar to
http://www.abcdex.in/deal/d29e96cfd623a83f37f1bc12b4465131
Convert the product name into a variable, such as $ProductName
Then redirect:
<?php
header("Location: http://www.abcdex.in/deal/'.$ProductName.'");
?>
It is better if you alter the header into a 301 moved permanently, but you will only be able to alter the header if the Product-Name is passed into the variable $ProductName before any parts of the page have been loaded.
header("HTTP/1.1 301 Moved Permanently");
If you can't alter the header, then there are ways to redirect in PHP without using the header. I believe the following code works:
$URL="http://www.abcdex.in/deal/'.$ProductName.'";
echo '<META HTTP-EQUIV="refresh" content="0;URL=' . $URL . '">';
echo "<script type='text/javascript'>document.location.href='{$URL}'; </script>";
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.