2

How can I force Apache if URI start with "admin-" pattern or contain "admin/user/login" redirect to https of the same uri.

For example:

If the URI is :

http://examplesite.com/admin-2dns24dw 

Redirect to :

https://examplesite.com/admin-2dns24dw 

And if the URI is :

http://examplesite.com/en/admin/user/login/msg

redirect to :

https://examplesite.com/en/admin/user/login/msg

And if any https URI that hasn't any of this patterns should be redirect to http of same URL.

For example:

If the URI is :

https://examplesite.com/fa/dashboard

Redirect to :

http://examplesite.com/fa/dashboard

** UPDATE **

I tried:

 RewriteCond %{HTTPS} !=on
 RewriteCond %{THE_REQUEST} admin-|admin/users/login [NC]
 RewriteRule ^(my) https://%{HTTP_HOST}%{REQUEST_URI} [NC,R=301,L]

but it didn't worked.

whats the problem?

Arash Mousavi
  • 658
  • 3
  • 8
  • 21

2 Answers2

3

This is very simple using mod_rewrite:

RewriteEngine On
RewriteCond %{HTTPS} !=on
RewriteRule ^(foo|bar)$ https://%{SERVER_NAME}%{REQUEST_URI} [L,R]

This will rewrite any URL that matches the pattern in the RewriteRule to the same URL over HTTPS.

dawud
  • 14,918
  • 3
  • 41
  • 61
1

You can try mod_alias - Apache HTTP Server Redirect Directive.

Example:

Redirect /service http://foo2.example.com/service 

* UPDATE *

Redirect /admin-2dns24dw https://examplesite.com/fa/dashboard
alexus
  • 12,342
  • 27
  • 115
  • 173