Merge 2 mod_rewrite conditions into . htaccess

Asked

Viewed 289 times

2

About . htaccess and mod_rewrite understanding absolutely nothing!

The situation is as follows, I have 2 projects in different areas:

  1. This first project uses the condition below that directs the browser always to the HTTPS protocol by disabling HTTP browsing.

    RewriteEngine On
    RewriteCond %{HTTPS} off
    RewriteRule (.*) https://%{HTTP_HOST}%{REQUEST_URI}
    
  2. This second project uses the condition below that enables user-friendly URL browsing.

    RewriteEngine on
    RewriteCond %{SCRIPT_FILENAME} !-f
    RewriteCond %{SCRIPT_FILENAME} !-d
    RewriteRule ^(.*)$ index.php?url=$1
    

The question now is, I need to merge these conditions for a 3rd project, as it has SSL (HTTPS) enabled and also the rewrite to URL friendly.

1 answer

2


I believe so, just use one RewriteCond before his RewriteRule and it may also be necessary to use the flag [L]:

RewriteEngine On
RewriteCond %{HTTPS} off
RewriteRule (.*) https://%{HTTP_HOST}%{REQUEST_URI} [L]

RewriteCond %{SCRIPT_FILENAME} !-f
RewriteCond %{SCRIPT_FILENAME} !-d
RewriteRule ^(.*)$ index.php?url=$1

If you have any mistakes, let me know.

  • 1

    By William, by the logic I did exactly what I did only that without the flag, returned "Incorrect redirection" in the browser, just put the flag that had no knowledge that worked. Now I’ll read a link that posted on the flags rs, thanks!

Browser other questions tagged

You are not signed in. Login or sign up in order to post.