[英]Write page title in URL instead of page ID
我有我的网站,每当我向其中添加新页面时,它都会创建一个带有不需要的随机ID号的URL。 我想使用page/product
名称作为我的URL,所以我目前拥有的是:
当前: http://www.abcdex.in/deal/d29e96cfd623a83f37f1bc12b4465131
: http://www.abcdex.in/deal/d29e96cfd623a83f37f1bc12b4465131
期望的: http://www.abcdex.in/deal/Product-Name
: http://www.abcdex.in/deal/Product-Name
我遍历了.htaccess
文件,并在底部显示了以下代码:
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]
有人可以帮助我,因为它造成了很多混乱,因此我失去了网站排名?
先感谢您!
从此示例中学习并应用于您的.htaccess示例
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]
您的.htaccess文件将类似于您的文件名
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]
您可以尝试在htaccess中完成所有这些操作,但是我想用PHP解决这些问题
在您所有具有类似以下网址的网页上
http://www.abcdex.in/deal/d29e96cfd623a83f37f1bc12b4465131
将产品名称转换为变量,例如$ ProductName
然后重定向:
<?php
header("Location: http://www.abcdex.in/deal/'.$ProductName.'");
?>
最好将标头更改为永久移动的301,但只有在将页面的任何部分加载之前将产品名称传递到变量$ ProductName中的情况下,才能更改标头。
header("HTTP/1.1 301 Moved Permanently");
如果您无法更改标头,则可以使用PHP重定向而无需使用标头。 我相信以下代码可以工作:
$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>";
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.