【发布时间】: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/aboutus 到 www.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