【问题标题】:.htaccess SEO friendly url.htaccess SEO 友好的网址
【发布时间】:2017-05-14 09:50:33
【问题描述】:

我正在尝试为我的主页创建一个 SEO 友好的 URL。例如,我希望 example.com?url=hello-world 成为 example.com/hello-world。我当前的 .htaccess 有以下内容:

RewriteEngine On

RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^([^\.]+)$ $1.php [NC,L]

它可以正确删除 .php 文件扩展名,但我怎样才能使它也可以为主页生成一个 SEO 友好的 url?该文件是 index.php。

【问题讨论】:

    标签: apache .htaccess mod-rewrite


    【解决方案1】:

    试试这个,

    RewriteEngine On
    
    #remove .php    
    RewriteCond %{REQUEST_FILENAME}.php -f
    RewriteRule ^([^\.]+)$ $1.php [NC,L]
    
    #for pretty url
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteRule ^([^\.]+)$ index.php?url=$1 [NC,L]
    

    【讨论】:

      猜你喜欢
      • 2016-03-11
      • 2014-07-26
      • 2010-10-24
      • 2016-02-02
      • 2013-03-20
      • 2011-07-23
      • 2011-04-06
      • 2014-01-14
      • 2012-10-15
      相关资源
      最近更新 更多