我正在使用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,可以在address窗口中输入相同的内容,但它将重定向到最低级别,即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中的一些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>任何帮助都很感激。
发布于 2014-06-09 23:47:44
查看文档文件夹中的示例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]https://stackoverflow.com/questions/22518949
复制相似问题