简体   繁体   English

动态301 .htaccess默认页面

[英]Dynamic 301 .htaccess default page

I'm using Apache/PHP/MySql as the environment for a CMS, and one of the modules I've written for it allows the user to define any page as the root page for the site. 我使用Apache / PHP / MySql作为CMS的环境,为此编写的模块之一允许用户将任何页面定义为站点的根页面。 What I would like to do is allow and automate the process of redirecting the page's url such as for example "http://mysite.com/?page=home" to "http://mysite.com/". 我想做的是允许并自动执行将页面URL重定向的过程,例如将“ http://mysite.com/?page=home”重定向到“ http://mysite.com/”。

I've got the .htaccess hard-coded to look for a common default page name of "home" using this: 我已经将.htaccess进行了硬编码,以使用以下命令查找常见的默认页面名称“ home”:

RewriteCond %{QUERY_STRING} ^(.*)page=home$
RewriteRule ^$ /? [R=301,L]

But what I'd like to do is make it so the user doesn't have to touch the .htaccess file and it would automatically be updated when a default page is chosen from within the CMS. 但是我想做的是制作它,以便用户不必触摸.htaccess文件,当从CMS中选择默认页面时,它将自动更新。 I'm assuming I could use a comment to start and end the rewrite portion of .htaccess, but at this point I'm kinda lost without a good place to start. 我假设我可以使用注释来开始和结束.htaccess的重写部分,但是在这一点上,我有点迷茫,没有一个好的起点。 Any help would be greatly appreciated. 任何帮助将不胜感激。

Try this: 尝试这个:

If the query string starts with page=home then redirect 如果查询字符串以page=home开头,则重定向

RewriteCond %{QUERY_STRING} ^page=home$
RewriteRule ^$ /? [R=301,L]

I think you would use home as default home page, no matter what home default page is chosen by the user, so make changes into CMS and dont create/edit .htaccess files 我认为无论用户选择哪个默认主页,您都将home作为默认主页使用,因此请更改CMS并不要创建/编辑.htaccess文件

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM