LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Server (https://www.linuxquestions.org/questions/linux-server-73/)
-   -   mod_rewrite syntax (https://www.linuxquestions.org/questions/linux-server-73/mod_rewrite-syntax-936185/)

Iyyappan 03-24-2012 12:33 PM

I have been using the apache which came along with distro. But wanted to try from source too. In the apache which came along with distro has (conf conf.d logs modules run) folders alone, but while i install from source i get (bin build cgi-bin conf error htdocs icons include lib logs man manual modules). Y is that in normal apache(distro) the errors, libs, include folders are not there.

bathory 03-24-2012 12:54 PM

Quote:

Y is that in normal apache(distro) the errors, libs, include folders are not there.
This is because the distro maintainer compiles apache using specific options, so that the apache libs go under the system libs directory, the apache header files are installed under the system include dir and so on.

Iyyappan 03-24-2012 01:02 PM

Which do u think is better. I would go with Apache from source as all are placed in a specific folder. Can the redirect can be done using .htaccess too ? or only url redirect is possible using .htaccess

bathory 03-24-2012 01:20 PM

Quote:

Which do u think is better. I would go with Apache from source as all are placed in a specific folder.
Well, I'm always running apache compiled from source, so you can guess my opinion ;)

Quote:

Can the redirect can be done using .htaccess too ? or only url redirect is possible using .htaccess
Don't get what you mean by that. The redirect, as well as URL rewriting can be done either using .htaccess or using the relevant directives in httpd.conf, or other apache config files.

Iyyappan 03-24-2012 01:30 PM

redirecting http to https was done using rewrite_module. Is it possible to do the same using .htaccess?

bathory 03-24-2012 01:42 PM

Quote:

Originally Posted by Iyyappan (Post 4635250)
redirecting http to https was done using rewrite_module. Is it possible to do the same using .htaccess?

Of course it is.

Iyyappan 03-26-2012 12:03 AM

Once https redirect is enabled. All the sites below will be accessed via https right. Bcoz now i have only one small index file for testing. With the RewriteEngine syntax the entire sub folders below it will be accessed via https right.

Then what is the difference between
1.Redirect permanent / https://www.mytest.com/
2. Using Rewrite Module

Also in the following syntax
RewriteEngine on​
RewriteCond %{SERVER_PORT} =443
RewriteRule ^/(.*) https://%{HTTP_HOST}/$1 [NC,R,L]

I would be happy if you explain the RewriteCond and RewriteRule with the various possibilities

bathory 03-26-2012 02:07 AM

Quote:

Once https redirect is enabled. All the sites below will be accessed via https right. Bcoz now i have only one small index file for testing. With the RewriteEngine syntax the entire sub folders below it will be accessed via https right.
If you use rewrite inside the apache config files and not in .htaccess, then you can redirect all your sites into their https counterparts


Quote:

Then what is the difference between
1.Redirect permanent / https://www.mytest.com/
2. Using Rewrite Module
In your case there is no difference
You use mod_rewrite when you want to do url rewriting based on certain conditions, or some fancy redirecting and so on.


Quote:

Also in the following syntax
RewriteEngine on​
RewriteCond %{SERVER_PORT} =443
RewriteRule ^/(.*) https://%{HTTP_HOST}/$1 [NC,R,L]

I would be happy if you explain the RewriteCond and RewriteRule with the various possibilities
The rewrite above is not going to work
Apache looks the port it got the request and evaluates it against the RewriteCond(ition). If it's port 443 then it does the rewrite as specified by the RewriteRule, i.e. from plain http to https. Of course in this case you're going to have a loop, as the port will be always 443 and apache will always redirect the request to https
If you want, you can have have a look at the apache mod_rewrite documentation for better understanding.

Regards

Iyyappan 03-26-2012 02:10 AM

thanks for providing the details

Iyyappan 03-26-2012 02:28 AM

In Apache installed from source(/usr/local/apache) in the httpd.conf file the user and group is showing as daemon. In apache which came with distro(/etc/httpd) is showing as apache. In /etc/passwd Apache user points to /var/www. Now can i change the user and group to apache in /usr/local/apache/conf/httpd.conf and in /etc/passwd i change the document root to /usr/local/apache/htdocs right. Or should i completely remove httpd(distro) and do this..

bathory 03-26-2012 02:50 AM

I would suggest you to remove the apache that came with your distro.
The apache user homedir is irrelevant. What you need to do, is to make sure that the actual docroot is owned by the apache user you used in httpd.conf, e.g.
Code:

chown -R daemon /usr/local/apache/htdocs

Iyyappan 03-26-2012 05:38 AM

What must be the owner and group of Apache Web Server. Can the entire Web server be like this

drwxr-xr-x 15 apache apache 4096 Mar 24 23:06 apache

or

drwxr-xr-x 15 apache root 4096 Mar 24 23:06 apache

or

changing rights for htdocs alone to apache is enough.

Can u specify the owner, group and rights which must be assigned for entire Apache Web Server for it to be a secured one

bathory 03-26-2012 09:35 AM

Quote:

changing rights for htdocs alone to apache is enough.
You should change the rights only for the htdocs directory (and subdirs)
The rest of the apache files, should be owned by root:root

Regards

Iyyappan 03-26-2012 10:46 PM

What the permissions to be set for entire apache files

bathory 03-26-2012 11:48 PM

Quote:

Originally Posted by Iyyappan (Post 4637209)
What the permissions to be set for entire apache files

Better not mess with the file permissions. Leave them as they were set by the installation.


All times are GMT -5. The time now is 01:26 PM.