简体   繁体   中英

htaccess simple rewrite rule doesn't work

I've never did rewrite rules and everything I try out and find at google doesn't work. Especially creating multiple rewrite rules is hard for me because I don't know how the right syntax is and how a proper implementation looks like (1 Rewrite Condition or multiple and similar questions).

Thus I would be happy to get a result for my following try:

https://www.domain.com/our_accounts.php -> https://www.domain.com/accounts

The http -> https rule is already working. Maybe there is also the problem with my rewrite rules because I may need to add them before my https rules ?? I hope you guys can help me with this.

<IfModule mod_rewrite.c>
    RewriteEngine On
    RewriteCond %{HTTPS} off
    # First rewrite to HTTPS:
    RewriteRule ^(.*)$ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
    # Now, rewrite any request to the wrong domain to use www.
    RewriteCond %{HTTP_HOST} !^www\.
    RewriteRule ^(.*)$ https://www.%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
    # Rules for readable URLs
    RewriteCond %{THE_REQUEST} ^.*/index\.php 
    RewriteRule ^(.*)index.php$ /$1 [R=301,L]
    RewriteRule ^accounts$ /our_accounts.php [L]
</IfModule>

Try your htacess file this way. I also condensed the HTTP and www to one rewrite rule. Just replace yoursite.com with your real site.

<IfModule mod_rewrite.c>
    RewriteEngine On
     # First rewrite to HTTPS and redirect www:
    RewriteCond %{HTTPS} !^on [OR]
    RewriteCond %{HTTP_HOST} !^www\.
    RewriteRule ^(.*)$ https://www.yoursite.com/$1 [L,R=301]

    RewriteRule ^our_accounts.php$ /accounts [R=301,L]

    # Rules for readable URLs
    RewriteCond %{THE_REQUEST} ^.*/index\.php 
    RewriteRule ^(.*)index.php$ /$1 [R=301,L]
</IfModule>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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