簡體   English   中英

在URL中寫頁面標題而不是頁面ID

[英]Write page title in URL instead of page ID

我有我的網站,每當我向其中添加新頁面時,它都會創建一個帶有不需要的隨機ID號的URL。 我想使用page/product名稱作為我的URL,所以我目前擁有的是:

當前: http://www.abcdex.in/deal/d29e96cfd623a83f37f1bc12b4465131http://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.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM