在URL而不是页面ID中写入页面标题

时间:2016-11-18 06:42:13

标签: javascript php web e-commerce

我有我的网站,每当我在其中添加新页面时,它会创建一个我不想要的随机ID号码的网址。我想使用page/product名称作为我的网址,因此我目前所拥有的是:

目前:http://www.abcdex.in/deal/d29e96cfd623a83f37f1bc12b4465131

所需: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]

有没有人可以帮助我,因为它造成了很多混乱,我因此失去了我的网站排名?

提前谢谢!

2 个答案:

答案 0 :(得分:0)

从这个例子中学习并应用于你的.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]

答案 1 :(得分:0)

您可以尝试在htaccess中完成所有这些操作,但我喜欢在PHP中解决这些问题

在您的所有网页上使用类似于

的网址
http://www.abcdex.in/deal/d29e96cfd623a83f37f1bc12b4465131

将产品名称转换为变量,例如$ ProductName

然后重定向:

 <?php 
 header("Location: http://www.abcdex.in/deal/'.$ProductName.'"); 
 ?>

最好将标题更改为永久移动的301,但如果在加载页面的任何部分之前将Product-Name传递到变量$ ProductName,则只能更改标题。 / p>

 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>";
相关问题