mod_rewrite not working htaccess

后端 未结 3 930
孤街浪徒
孤街浪徒 2021-01-27 04:21

I have a website with 11 sub-domains.I have one main htaccess file in the public_html root folder that has the common shared traits like cache

3条回答
  •  误落风尘
    2021-01-27 05:21

    This will make /thursday work (and all the other days), put it in your main .htaccess and in your sub-domain ones. It will also redirect your old URLs to the new ones.

    It will only work if you are on Apache 2.4 or later. Let me know if you're not and I'll update the answer.

    RewriteEngine on
    
    # Redirect old URLs
    RewriteCond %{QUERY_STRING} =day=mon
    RewriteRule ^days/content\.php$ /monday [R=301,END]
    RewriteCond %{QUERY_STRING} =day=tue
    RewriteRule ^days/content\.php$ /tuesday [R=301,END]
    RewriteCond %{QUERY_STRING} =day=wed
    RewriteRule ^days/content\.php$ /wednesday [R=301,END]
    RewriteCond %{QUERY_STRING} =day=thur
    RewriteRule ^days/content\.php$ /thursday [R=301,END]
    RewriteCond %{QUERY_STRING} =day=fri
    RewriteRule ^days/content\.php$ /friday [R=301,END]
    RewriteCond %{QUERY_STRING} =day=sat
    RewriteRule ^days/content\.php$ /saturday [R=301,END]
    RewriteCond %{QUERY_STRING} =day=sun
    RewriteRule ^days/content\.php$ /sunday [R=301,END]
    
    # Rewrite new URLs
    RewriteRule ^monday$ days/content.php?day=mon [END]
    RewriteRule ^tuesday$ days/content.php?day=tue [END]
    RewriteRule ^wednesday$ days/content.php?day=wed [END]
    RewriteRule ^thursday$ days/content.php?day=thur [END]
    RewriteRule ^friday$ days/content.php?day=fri [END]
    RewriteRule ^saturday$ days/content.php?day=sat [END]
    RewriteRule ^sunday$ days/content.php?day=sun [END]
    

    It is best to do the days individually since the script uses a short form and the new URL doesn't. You can change them if needed, or let me know if I'm missing something.

提交回复
热议问题