How to redirect my URL

Alles, was den Apache betrifft, kann hier besprochen werden.

How to redirect my URL

Postby samaka4you » 20. September 2008 15:40

Hi,

It's my first post in this forum. Hoping not be the last one.

I have one site https://mysite/myforlder/ working very well (combinaosioj of Apache + Tomcat in Mod_JK)

I want when I consult http://mysite/ (http not https and without writing myforlder in the URL), this URL will ben redirected to https://mysite/myforlder automatically

For your information, I have added the command "RewriteRule ^/$ https://mysite" which enable to redirect the URL http://mysite/myforlder/ vers https://mysite/myforlder/

Thanks upfront for your help.
samaka4you
 
Posts: 4
Joined: 20. September 2008 15:39

Postby glitzi85 » 21. September 2008 21:03

OK, if i understood you correct, you want to redirect it in this way:

http://example/ -> https://example/folder
https://example/ -> https://example/folder

So i would do it in this way:

Code: Select all
RewriteRule ^/$ https://%{SERVER_NAME}/folder [L,R]
RewriteCond %{SERVER_PORT} !^443$
RewriteRule ^(.*)$ https://%{SERVER_NAME}%{REQUEST_URI} [L,R]


glitzi
User avatar
glitzi85
 
Posts: 1920
Joined: 05. March 2004 23:26
Location: Dahoim

Postby samaka4you » 23. September 2008 10:44

Thanks for your repliyn.

In fact, I want jsute to redirect it in this way :

http://example/ -> https://example/folder

When I put your configuration, I have the same probleme. I mean, when I consult the following URL http://example/ I have the following error :

Not Found

The requested URL / was not found on this server.

when I consult the following URL http://example/folder I have a pretty redirection to my application's home page.

What shall I do?

Thanks in advance.
samaka4you
 
Posts: 4
Joined: 20. September 2008 15:39

Postby glitzi85 » 23. September 2008 14:37

Please post your complete configuration.

glitzi
User avatar
glitzi85
 
Posts: 1920
Joined: 05. March 2004 23:26
Location: Dahoim

Postby samaka4you » 23. September 2008 15:35

Below, the whole configuration of my virtual site :

machine:~# vi /etc/apache2/sites-enabled/mysite

Alias /myfolder /usr/local/tomcat/webapps/myfolder

JkMount /*.jsp worker1
JkMount /servlet/* worker1
JkMount /josso/* worker1
JkMount /myfolder/* worker1

NameVirtualHost machine:80

<VirtualHost machine:80>
ServerName mysite
<IfModule mod_rewrite.c>

RewriteEngine on
# RewriteCond %{SERVER_PORT} !^443$
# RewriteRule ^/(.*) https://mysite/$1 [L,R]

#RewriteRule ^/$ https://mysite

#Rewriterule ^/(.*)$ https://mysite/myfolder/$1 [R,L]

RewriteRule ^/$ https://%{SERVER_NAME}/myfolder [L,R]
RewriteCond %{SERVER_PORT} !^443$
RewriteRule ^(.*)$ https://%{SERVER_NAME}%{REQUEST_URI} [L,R]

</IfModule>
</VirtualHost>

<Directory /usr/local/tomcat/>
Options FollowSymLinks
AllowOverride None
Order allow,deny
Allow from all
</Directory>

NameVirtualHost machine:443

<VirtualHost machine:443>
ServerName mysite
ErrorLog /var/log/apache2/mysite_error.log


# Possible values include: debug, info, notice, warn, error, crit,
# alert, emerg.
LogLevel warn

CustomLog /var/log/apache2/mysite_access.log combined


Thanks in advance
samaka4you
 
Posts: 4
Joined: 20. September 2008 15:39

Postby samaka4you » 03. October 2008 12:03

No reply ?

Yours truly
samaka4you
 
Posts: 4
Joined: 20. September 2008 15:39

Postby glitzi85 » 03. October 2008 16:04

OK, in this case you can just use this rule:

Code: Select all
RewriteEngine On
RewriteRule ^.*$ https://%{SERVER_NAME}/myfolder [L,R]


In this case every request on Port 80 will be redirected to https://example.com/myfolder

glitzi
User avatar
glitzi85
 
Posts: 1920
Joined: 05. March 2004 23:26
Location: Dahoim


Return to Apache

Who is online

Users browsing this forum: No registered users and 5 guests