【问题标题】:I need to change my url seo friendly with url routing我需要通过 url 路由更改我的 url seo 友好
【发布时间】:2016-07-04 17:24:29
【问题描述】:

我需要知道如何更改我的网站 url 我尝试使用 url 路由什么不起作用 我的网站产品网址是http://www.shahilibas.in/product.php?p_id=5,我想要像http://www.shahilibas.in/product.php/5 这样的seo 友好网址 我尝试使用此代码进行 url 路由

function getCurrentUri()
{
    $basepath = implode('/', array_slice(explode('/',      $_SERVER['SCRIPT_NAME']), 0, -1)) . '/';
    $uri = substr($_SERVER['REQUEST_URI'], strlen($basepath));
    if (strstr($uri, '?')) $uri = substr($uri, 0, strpos($uri, '?'));
    $uri = '/' . trim($uri, '/');
    return $uri;
    echo $uri;
}

【问题讨论】:

标签: javascript php jquery


【解决方案1】:

您需要将重写规则添加到 .htaccess 文件。创建新的文本文件,将其命名为“.htaccess”,不带引号。

在您的 .htaccess 文件中编写下面的代码并按 Ctrl + s 保存您的文件

Options +FollowSymLinks
RewriteEngine On

RewriteCond %{SCRIPT_FILENAME} !-d
RewriteCond %{SCRIPT_FILENAME} !-f


RewriteRule ^(\w+)$ ./serve.php?short=$1

【讨论】:

    【解决方案2】:

    您可以在 .htaccess 文件中添加以下代码并保存

    <IfModule mod_rewrite.c>
    
        Options +FollowSymlinks
    
        RewriteEngine On
        RewriteRule ^([a-zA-Z0-9_-]+)$ products.php?p_id=$1
        RewriteRule ^([a-zA-Z0-9_-]+)/$ products.php?p_id=$1
    
    </IfModule>
    

    那么你的网址会是这样的 http://www.shahilibas.in/5

    哪个网址更友好。在 url 中显示 php 文件对 SEO 不利。

    【讨论】:

      猜你喜欢
      • 2012-10-06
      • 2011-12-24
      • 2011-04-06
      • 2012-03-29
      • 1970-01-01
      • 1970-01-01
      • 2012-01-17
      • 2011-11-21
      • 2011-08-25
      相关资源
      最近更新 更多