2016-11-18 47 views
0

我有我的网站,每当我添加一个新网页时,它都会创建一个带有随机ID号的网址,我不想要。我想用page/product名称作为我的网址,所以我有什么现在是:在网址中写网页标题而不是网页ID

电流: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] 

谁能帮我,因为它创造了很多乱七八糟的,我失去,因为这是我的网站排名?

预先感谢您!

+0

这就是所谓的'人类可读URL'并且最好是在你的含量的不同管理体制层面解决这一问题 - 即管理你的网站系统。在那里检查选项'人类可读网址' – SergeyLebedev

+0

当提交表单时会更改网址吗?也就是当你点击一个产品时? – GraveyardQueen

+0

@kapil sharma我已经贴上了一个exampler从中学习,如果有任何怀疑可以随意问,请在那里应用。 –

回答

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] 
0

你可以尝试做这一切htaccess的,但我喜欢用PHP解决这些问题

在您的所有网页上的网址类似于

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

转换的产品名称到一个变量,如$产品名称

然后重定向:

<?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>";