开发者

Dynamic 301 .htaccess default page

开发者 https://www.devze.com 2023-04-04 12:52 出处:网络
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. What I would like to do is allow

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. 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/".

I've got the .htaccess hard-coded to look for a common default page name of "home" using this:

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. 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. Any hel开发者_如何学Cp would be greatly appreciated.


Try this:

If the query string starts with page=home then redirect

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

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号