【问题标题】:.htaccess to provide 'flattened' search engine friendly CMS URLs.htaccess 提供“扁平化”搜索引擎友好的 CMS URL
【发布时间】:2014-04-26 11:17:28
【问题描述】:

我正在将 CMSMADESIMPLE 用于网站。它可以使用 .htaccess 文件和 mod_rewrite 生成搜索引擎友好的 URL。

但是可以在基本 url 和请求的页面之间插入任何内容。例如,所有这些 URL 都可以使用:

www.example.com/aboutus
www.example.com/home/aboutus
www.example.com/any/rubbish/i/enter/aboutus

我看到其他使用 Wordpress 的网站可以在地址窗口中输入相同的内容,但它会重定向回最低级别,即 www.example.com/aboutus。我想实现同样的目标,但无法掌握 .htaccess 来做到这一点。

.htaccess 文件的相关位是:

<IfModule mod_rewrite.c>
RewriteEngine on
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.+)$ index.php?page=$1 [QSA]
</IfModule>

我假设这可以通过使用 mod_rewrite 来实现,并且不需要更改 CMS 中的 PHP 代码。

如果这不可能,我想从 CMS 中已被 Google 索引的某些 URL 设置永久重定向。

即从 www.example.com/home/aboutuswww.example.com/aboutus

我尝试将 RewriteRule 添加到 .htaccess 但没有成功:

<IfModule mod_rewrite.c>
RewriteEngine on
RewriteBase /
RewriteRule home/aboutus aboutus [R=301]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.+)$ index.php?page=$1 [QSA]
</IfModule>

任何帮助表示赞赏。

【问题讨论】:

    标签: mod-rewrite


    【解决方案1】:

    查看 doc 文件夹中的示例 htaccess.txt 文件。有一个关于父子的部分。

        # Rewrites urls in the form of /parent/child/
        # but only rewrites if the requested URL is not a file or directory
        #
        RewriteCond %{REQUEST_FILENAME} !-f
        RewriteCond %{REQUEST_FILENAME} !-d
        RewriteRule ^(.+)$ index.php?page=$1 [QSA]
    

    【讨论】:

      猜你喜欢
      • 2021-06-12
      • 2012-06-18
      • 2011-12-24
      • 1970-01-01
      • 1970-01-01
      • 2011-08-31
      • 1970-01-01
      • 2013-10-16
      • 2014-11-09
      相关资源
      最近更新 更多