I would like to create an .htaccess to
- allow origin (https://www.example.com and https://example.com and https://subdomain.example.com)
- force https
- force www
- rewrite url with the subdirectory
Edit: Here is my new .htaccess file
RewriteEngine on
Header add Access-Control-Allow-Origin "https://www.example.com, https://example.com, https://subdomain.example.com"
Header add Access-Control-Allow-Methods "PUT, GET, POST, DELETE, OPTIONS"
Header add Access-Control-Allow-Headers "origin, x-requested-with, content-type, X-CSRF-Token"
RewriteCond %{HTTP_HOST} !^www\. [NC,OR]
RewriteCond %{HTTPS} off
RewriteCond %{HTTP_HOST} ^(?:www\.)?(.+)$ [NC]
RewriteRule ^ https://www.%1%{REQUEST_URI} [L,R=301,NE]
RewriteRule ^(path/to/directory/file)/([^/]+)/?$ $1.php?u=$2 [NC,L,QSA]
Here is my .htaccess file
RewriteEngine on
Header add Access-Control-Allow-Origin "https://www.example.com, https://example.com, https://subdomain.example.com"
Header add Access-Control-Allow-Methods "PUT, GET, POST, DELETE, OPTIONS"
Header add Access-Control-Allow-Headers "origin, x-requested-with, content-type, X-CSRF-Token"
RewriteCond %{HTTP_HOST} ^example\.com$ [OR]
RewriteCond %{HTTP_HOST} ^www\.example\.com$
RewriteCond %{SERVER_PORT} 80
RewriteRule ^(.*)$ "https\:\/\/www\.example\.com\/$1" [R=301]
RewriteRule ^path/to/directory/file/([^/]*)$ path/to/directory/file.php?u=$1 [L]
This rule is working: (http://example.com/file/xxxx)
RewriteRule ^file/([^/]*)$ path/to/directory/file.php?u=$1 [L]
Edit: This rule is working (http://example.com/path/to/directory/file/xxxx)
RewriteRule ^path/to/directory/file/([^/]*)$ path/to/directory/file.php?u=$1 [L]
Edit:
Think to remove the first slash after ^ to make it working as said in this subject.