mod_rewrite not working htaccess

后端 未结 3 902
孤街浪徒
孤街浪徒 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:01

    My apologies, I was the one using a bad folder directory system in my website. This is the one is was using

    public_html(www directory) -index.php -vidz(sub-domain) -index.php -days -_imports -css -js -php -content.php -contact.php

    This is my upgraded system

    public_html(www directory) -index.php -vidz(sub-domain) -index.php -content.php -contact.php -assets -_imports -css -js -php

    Which makes it possible to have the links as <a href='monday'>Mon</a> and use the .htaccess redirect rules below.

    <IfModule mod_rewrite.c>
    
        Options +FollowSymlinks
        RewriteEngine On   
        RewriteRule ^monday$ content.php?day=mon [NC,L]
        RewriteRule ^tuesday$ content.php?day=tue [NC,L]
        RewriteRule ^wednesday$ content.php?day=wed [NC,L]
        RewriteRule ^thursday$ content.php?day=thur [NC,L]
        RewriteRule ^friday$ content.php?day=fri [NC,L]
        RewriteRule ^saturday$ content.php?day=sat [NC,L]
        RewriteRule ^sunday$ content.php?day=sun [NC,L]
        RewriteRule ^contact$ contact.php [NC,L]
    
    </IfModule>

    Thanks to all who answered! It helped me realize this.

    0 讨论(0)
  • 2021-01-27 05:02

    Both Apache and nginx have the concept of internal and external redirects.

    What you could do to accomplish your task is create a "redirect loop", where /days/content.php?day=thur would redirect/R (external redirect) to /thursday, whereas /thursday would internally go back to /days/content.php?day=thur, which may initially look like a loop.

    See:

    • nginx redirect loop, remove index.php from url

    This could be done by testing against the request uri in each case:

    RewriteCond %{REQUEST_URI} ^/days/content.php$
    RewriteCond %{QUERY_STRING} ^day=thur$
    RewriteRule ^(.*)$ /thursday? [R,L] # external redirect
    
    RewriteCond %{REQUEST_URI} ^/thursday$
    RewriteRule ^(.*)$ /days/content.php?day=thur [L] # internal redirect
    
    0 讨论(0)
  • 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.

    0 讨论(0)
提交回复
热议问题