How to exclude a URL from HTTPS - apache

I have tried different links to see if it works, however it doesn't seems to work. I have configured https on Redhat EL6. However i wanted to have an exception from one of the IP.
I wanted to have https enabled for all except one IP 192.168.1.1. When i access the URL from the IP 192.168.1.1, it should get redirected or rewritten to http://cab.abc.com and not to https://cab.abc.com
Snip of my /etc/httpd/conf/httpd.conf :
<VirtualHost *:80>
DocumentRoot /opt/app/cr/public
ServerName cab.abc.com
RewriteEngine On
RewriteLog /var/tmp/rewrite.log
RewriteLogLevel 5
RewriteCond %{REMOTE_ADDR} ^192\.168\.1\.1
# RewriteRule .* http://cab.abc.com%{REQUEST_URI} [R]
# RewriteRule ^/(.*) http://cab.abc.com%{REQUEST_URI} [R]
RewriteRule .* http://cab.abc.com [L]
RewriteCond %{THE_REQUEST} ^(.*)
RewriteRule .* https://cab.abc.com%{REQUEST_URI} [R]
# ProxyPass / https://cab.abc.com/
# ProxyPassReverse / https://cab.abc.com/
</VirtualHost>
I have tried multiple options and checked the rewrite.log file :
192.1681.1 - - [21/Apr/2016:20:36:01 +0000] [cab.abc.com/sid#7fe3e21fe2e0][rid#7fe3e24c9b48/initial] (2) rewrite '/' -> 'http://cab.abc.com'
192.1681.1 - - [21/Apr/2016:20:36:01 +0000] [cab.abc.com/sid#7fe3e21fe2e0][rid#7fe3e24c9b48/initial] (2) implicitly forcing redirect (rc=302) with http://cab.abc.com
192.1681.1 - - [21/Apr/2016:20:36:01 +0000] [cab.abc.com/sid#7fe3e21fe2e0][rid#7fe3e24c9b48/initial] (1) escaping http://cab.abc.com for redirect
192.1681.1 - - [21/Apr/2016:20:36:01 +0000] [cab.abc.com/sid#7fe3e21fe2e0][rid#7fe3e24c9b48/initial] (1) redirect to http://cab.abc.com [REDIRECT/302]
192.1681.1 - - [21/Apr/2016:20:36:01 +0000] [cab.abc.com/sid#7fe3e21fe2e0][rid#7fe3e24c9b48/initial] (2) init rewrite engine with requested uri /
192.1681.1 - - [21/Apr/2016:20:36:01 +0000] [cab.abc.com/sid#7fe3e21fe2e0][rid#7fe3e24c9b48/initial] (3) applying pattern '.*' to uri '/'
192.1681.1 - - [21/Apr/2016:20:36:01 +0000] [cab.abc.com/sid#7fe3e21fe2e0][rid#7fe3e24c9b48/initial] (4) RewriteCond: input=‘192.168.1.1’ pattern='^192\\.168\\.1\\.1’ => matched
192.1681.1 - - [21/Apr/2016:20:36:01 +0000] [cab.abc.com/sid#7fe3e21fe2e0][rid#7fe3e24c9b48/initial] (2) rewrite '/' -> 'http://cab.abc.com'
192.1681.1 - - [21/Apr/2016:20:36:01 +0000] [cab.abc.com/sid#7fe3e21fe2e0][rid#7fe3e24c9b48/initial] (2) implicitly forcing redirect (rc=302) with http://cab.abc.com
192.1681.1 - - [21/Apr/2016:20:36:01 +0000] [cab.abc.com/sid#7fe3e21fe2e0][rid#7fe3e24c9b48/initial] (1) escaping http://cab.abc.com for redirect
192.1681.1 - - [21/Apr/2016:20:36:01 +0000] [cab.abc.com/sid#7fe3e21fe2e0][rid#7fe3e24c9b48/initial] (1) redirect to http://cab.abc.com [REDIRECT/302]
192.1681.1 - - [21/Apr/2016:20:36:01 +0000] [cab.abc.com/sid#7fe3e21fe2e0][rid#7fe3e24c5b28/initial] (2) init rewrite engine with requested uri /
192.1681.1 - - [21/Apr/2016:20:36:01 +0000] [cab.abc.com/sid#7fe3e21fe2e0][rid#7fe3e24c5b28/initial] (3) applying pattern '.*' to uri '/'
192.1681.1 - - [21/Apr/2016:20:36:01 +0000] [cab.abc.com/sid#7fe3e21fe2e0][rid#7fe3e24c5b28/initial] (4) RewriteCond: input=‘192.1681.1.’ pattern='^192\\.168\\.1\\.1’ => matched
Requesting your help to exclude an IP address from HTTPs.

Try these rules after clearing browser cache:
RewriteEngine On
RewriteCond %{HTTPS} off
RewriteCond %{REMOTE_ADDR} !=192.168.1.1
RewriteRule ^ https://cab.abc.com%{REQUEST_URI} [R,L,NE]
RewriteCond %{REMOTE_ADDR} =192.168.1.1
RewriteRule ^ http://cab.abc.com%{REQUEST_URI} [R,L,NE]

Related

htaccess canonical URL subdirectory

I have the same problem as htaccess - canonical URL when redirecting to subdirectory, but the solution there appears to use a hardcoded host name in the htaccess file which I can't do.
The following is in my htaccess file in the root directory which works fine for redirecting all requests into the /public directory with the exception of node_modules:
<IfModule mod_rewrite.c>
RewriteEngine on
# Allow node_modules
RewriteRule ^node_modules($|/) - [L]
# Rewrite everything to public
RewriteRule ^(.*)$ public/$1 [L,QSA]
</IfModule>
However I realize that the pages can be accessed through two different URLs, for example:
https://localhost/application1/foo/books.php
https://localhost/application1/public/foo/books.php
How do I either prevent the second one (ideally) or have it redirect to the first one?
I tried various RewriteCond statements with %{THE_REQUEST} but they turned out to be infinite loops. As mentioned above this needs to be hostname-agnostic as the application runs on different environments.
Update
I tried #SuperDuperApps answer below with the following in my .htaccess, which seemed to make no difference:
RewriteEngine on
RewriteCond $1 !^node_modules($|/)
RewriteCond $1 !^public($|/)
RewriteRule ^(.*)$ public/$1 [L,QSA]
RewriteRule ^public/ - [L,R=404]
After enabling RewriteLogLevel 3 in my dev server, this is what appears when I access a file with /public in the URL:
192.168.33.1 - - [27/Jan/2017:22:52:45 --0500] [localhost/sid#7f4a0d1d2cf0][rid#7f4a0d6a5d58/initial] (1) [perdir /var/www/html/application1/public/] pass through /var/www/html/application1/public/common/assets/js/nav.min.js
And this is when I access the same file without /public in the URL (desired behaviour):
192.168.33.1 - - [27/Jan/2017:22:48:45 --0500] [localhost/sid#7f4a0d1d2cf0][rid#7f4a0d684738/initial] (3) [perdir /var/www/html/application1/] add path info postfix: /var/www/html/application1/common -> /var/www/html/application1/common/assets/js/nav.min.js
192.168.33.1 - - [27/Jan/2017:22:48:45 --0500] [localhost/sid#7f4a0d1d2cf0][rid#7f4a0d684738/initial] (3) [perdir /var/www/html/application1/] strip per-dir prefix: /var/www/html/application1/common/assets/js/nav.min.js -> common/assets/js/nav.min.js
192.168.33.1 - - [27/Jan/2017:22:48:45 --0500] [localhost/sid#7f4a0d1d2cf0][rid#7f4a0d684738/initial] (3) [perdir /var/www/html/application1/] applying pattern '^(.*)$' to uri 'common/assets/js/nav.min.js'
192.168.33.1 - - [27/Jan/2017:22:48:45 --0500] [localhost/sid#7f4a0d1d2cf0][rid#7f4a0d684738/initial] (2) [perdir /var/www/html/application1/] rewrite 'common/assets/js/nav.min.js' -> 'public/common/assets/js/nav.min.js'
192.168.33.1 - - [27/Jan/2017:22:48:45 --0500] [localhost/sid#7f4a0d1d2cf0][rid#7f4a0d684738/initial] (3) [perdir /var/www/html/application1/] add per-dir prefix: public/common/assets/js/nav.min.js -> /var/www/html/application1/public/common/assets/js/nav.min.js
192.168.33.1 - - [27/Jan/2017:22:48:45 --0500] [localhost/sid#7f4a0d1d2cf0][rid#7f4a0d684738/initial] (2) [perdir /var/www/html/application1/] strip document_root prefix: /var/www/html/application1/public/common/assets/js/nav.min.js -> /application1/public/common/assets/js/nav.min.js
192.168.33.1 - - [27/Jan/2017:22:48:45 --0500] [localhost/sid#7f4a0d1d2cf0][rid#7f4a0d684738/initial] (1) [perdir /var/www/html/application1/] internal redirect with /application1/public/common/assets/js/nav.min.js [INTERNAL REDIRECT]
192.168.33.1 - - [27/Jan/2017:22:48:45 --0500] [localhost/sid#7f4a0d1d2cf0][rid#7f4a0d676688/initial/redir#1] (1) [perdir /var/www/html/application1/public/] pass through /var/www/html/application1/public/common/assets/js/nav.min.js
This should do it:
RewriteEngine on
# Allow node_modules
RewriteCond $1 !^node_modules($|/)
# Rewrite everything to public except public
RewriteCond $1 !^public($|/)
RewriteRule ^(.*)$ public/$1 [L,QSA]
# 404 diret access to public
RewriteRule ^public/ - [L,R=404]
Got it working with two separate files.
.htaccess:
<IfModule mod_rewrite.c>
RewriteEngine on
# Allow node_modules
RewriteRule ^node_modules($|/) - [L]
# Rewrite everything to public
RewriteRule ^(.*)$ public/$1 [L,QSA]
</IfModule>
.htaccess inside public:
<IfModule mod_rewrite.c>
RewriteEngine on
# pass-through if another rewrite rule has been applied already
RewriteCond %{ENV:REDIRECT_STATUS} 200
RewriteRule .* - [S=1] # Skip the next rule
RewriteRule ^ - [L,R=404]
# ...additional rules here as needed
</IfModule>
[L] can have been used instead of [S=1] in the second file if there are no additional rules.
This question gave me the idea with "pass-through if redirect".
Also thanks to #SuperDuperApps for the debugging hint with RewriteLogLevel and the original answer with the [END] flag that may have worked if I had Apache 2.4.

mod_rewrite not finding files that exists

I am working on a project that uses Apache 2.2 and we are implementing a rewrite rule that uses the file on the local disk if it exists and if it doesn't then it using another server to server the file. To simplify the problem I have just put a rule in that redirects to a given URL if the file doesn't exist:
RewriteCond %{REQUEST_URI} !-f
RewriteRule ^(.*) /notfound.html
Now the output on that request from the rewrite log is as follows:
127.0.0.1 - - [30/May/2016:16:54:01 +1000] [www.blah.com/sid#7f8a4ee0f358][rid#7f8a4f45d7d8/initial] (2) init rewrite engine with requested uri /index.html
127.0.0.1 - - [30/May/2016:16:54:01 +1000] [www.blah.com/sid#7f8a4ee0f358][rid#7f8a4f45d7d8/initial] (3) applying pattern '^(.*)' to uri '/index.html'
127.0.0.1 - - [30/May/2016:16:54:01 +1000] [www.blah.com/sid#7f8a4ee0f358][rid#7f8a4f45d7d8/initial] (4) RewriteCond: input='/index.html' pattern='!-f' => matched
127.0.0.1 - - [30/May/2016:16:54:01 +1000] [www.blah.com/sid#7f8a4ee0f358][rid#7f8a4f45d7d8/initial] (2) rewrite '/index.html' -> '/notfound.html'
127.0.0.1 - - [30/May/2016:16:54:01 +1000] [www.blah.com/sid#7f8a4ee0f358][rid#7f8a4f45d7d8/initial] (2) local path result: /notfound.html
127.0.0.1 - - [30/May/2016:16:54:01 +1000] [www.blah.com/sid#7f8a4ee0f358][rid#7f8a4f45d7d8/initial] (2) prefixed with document_root to /var/www/html/notfound.html
127.0.0.1 - - [30/May/2016:16:54:01 +1000] [www.blah.com/sid#7f8a4ee0f358][rid#7f8a4f45d7d8/initial] (1) go-ahead with /var/www/html/notfound.html [OK]
When I turn off the rewrite rules and run the same command I get a 200 response from the server.
The server has permissions to view the file.
Any help would be appreciated.
Use %{REQUEST_FILENAME} instead of %{REQUEST_URI}, thus:
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*) /notfound.html
%{REQUEST_URI} will contain only /index.html, so it won't work unless the filesystem has an index.html file in the root.
%{REQUEST_FILENAME} will contain the full path to the requested filename (including the Apache directory root for that domain)
Note that REQUEST_URI and REQUEST_FILENAME might happen to be equal under some specific circumstances, but more often than not, they won't. So if you are checking for a filename in the server's local filesystem (as it's the case), use the specific.

apache redirect - condition not matched correctly

I have the following simple rewrite-statement and conditions in my virtualhost section of Apache (2.2) config
RewriteCond %{REQUEST_URI} !-d
RewriteCond %{REQUEST_URI} !-f
RewriteRule ^([^\.]{2,})$ /bootstrap.php?url=$1
All requests are nicely redirected to the bootstrap.php, execpt if the file exists. That works fine. However, if a directory exists, I'd expect Apache to run the DirectoryIndex for that directory, or show the contents of the directory (whatever setting I choose), but Apache directs the request to the bootstrap.php too. It seems that the first rewriteCond is somehow not correct. What am I doing wrong?
When doing a debug, and trying to load "localhost/img" (which exists) I get the following output
127.0.0.1 - - [14/Jan/2013:20:18:14 +0100] [localhost/sid#4cd5a8][rid#14442c0/initial] (2) init rewrite engine with requested uri /img/
127.0.0.1 - - [14/Jan/2013:20:18:14 +0100] [localhost/sid#4cd5a8][rid#14442c0/initial] (3) applying pattern '^([^\.]{2,})$' to uri '/img/'
127.0.0.1 - - [14/Jan/2013:20:18:14 +0100] [localhost/sid#4cd5a8][rid#14442c0/initial] (4) RewriteCond: input='/img/' pattern='!-d' => matched
127.0.0.1 - - [14/Jan/2013:20:18:14 +0100] [localhost/sid#4cd5a8][rid#14442c0/initial] (4) RewriteCond: input='/img/' pattern='!-f' => matched
127.0.0.1 - - [14/Jan/2013:20:18:14 +0100] [localhost/sid#4cd5a8][rid#14442c0/initial] (2) rewrite '/img/' -> '/bootstrap.php?url=/img/'
127.0.0.1 - - [14/Jan/2013:20:18:14 +0100] [localhost/sid#4cd5a8][rid#14442c0/initial] (3) split uri=/bootstrap.php?url=/img/ -> uri=/bootstrap.php, args=url=/img/
127.0.0.1 - - [14/Jan/2013:20:18:14 +0100] [localhost/sid#4cd5a8][rid#14442c0/initial] (2) local path result: /bootstrap.php
127.0.0.1 - - [14/Jan/2013:20:18:14 +0100] [localhost/sid#4cd5a8][rid#14442c0/initial] (2) prefixed with document_root to C:/webroot/zippyshoot/bootstrap.php
127.0.0.1 - - [14/Jan/2013:20:18:14 +0100] [localhost/sid#4cd5a8][rid#14442c0/initial] (1) go-ahead with C:/webroot/zippyshoot/bootstrap.php [OK]
Works fine when loading localhost/img/logo.png. Output of the debug log is then
127.0.0.1 - - [14/Jan/2013:20:27:56 +0100] [localhost/sid#4cd5a8][rid#237d978/initial] (2) init rewrite engine with requested uri /img/logo.png
127.0.0.1 - - [14/Jan/2013:20:27:56 +0100] [localhost/sid#4cd5a8][rid#237d978/initial] (3) applying pattern '^([^\.]{2,})$' to uri '/img/logo.png'
127.0.0.1 - - [14/Jan/2013:20:27:56 +0100] [localhost/sid#4cd5a8][rid#237d978/initial] (1) pass through /img/logo.png
what am I doing wrong?
I found the answer to the question in this post
http://amandine.aupetit.info/135/apache2-mod_rewrite/
As from Apache 2.2, the rewriteCond is changed. The correct way to write them is now
RewriteCond %{DOCUMENT_ROOT}%{REQUEST_FILENAME} !-f
RewriteCond %{DOCUMENT_ROOT}%{REQUEST_FILENAME} !-d
RewriteCond %{DOCUMENT_ROOT}%{REQUEST_FILENAME} !-l

rewrite URL for PUT request

I changed the way my URL are working on my server.
It is now www.myserver.com/service instead of www.myserver.com/test/service
I have added a RedirectMatch 301 to my Apache conf file to redirect any access to www.myserver.com/test to www.myserver.com/.
I am receiving file to this server via an HTTP PUT at this URL for example :
www.myserver.com/test/service/put/myfile.xml
The server sending the file don't handle the 301 HTTP status code so the files didn't arrived anymore.
Is there a way to rewrite the URL when it is a PUT Request in order to don't miss any file?
Thanks,
Benjamin
UPDATE :
Here is the RewriteLog content after applying this :
RewriteEngine on
RewriteCond %{REQUEST_METHOD} =PUT
RewriteRule ^/test/(.*) /$1 [PT]
log :
XX.XXX.XXX.XXX - - [16/May/2010:06:33:40 +0000] [www.myserver.com/sid#7f378508aa30][rid#7f378538a828/initial] (2) init rewrite engine with requested uri /test/service/put/myfile.xml
XX.XXX.XXX.XXX - - [16/May/2010:06:33:40 +0000] [www.myserver.com/sid#7f378508aa30][rid#7f378538a828/initial] (3) applying pattern '^/test/(.*)' to uri '/test/service/put/myfile.xml'
XX.XXX.XXX.XXX - - [16/May/2010:06:33:40 +0000] [www.myserver.com/sid#7f378508aa30][rid#7f378538a828/initial] (4) RewriteCond: input='PUT' pattern='=PUT' => matched
XX.XXX.XXX.XXX - - [16/May/2010:06:33:40 +0000] [www.myserver.com/sid#7f378508aa30][rid#7f378538a828/initial] (2) rewrite '/test/service/put/myfile.xml' -> '/service/put/myfile.xml'
XX.XXX.XXX.XXX - - [16/May/2010:06:33:40 +0000] [www.myserver.com/sid#7f378508aa30][rid#7f378538a828/initial] (2) forcing '/service/put/myfile.xml' to get passed through to next API URI-to-filename handler
XX.XXX.XXX.XXX - - [16/May/2010:06:33:40 +0000] [www.myserver.com/sid#7f378508aa30][rid#7f3785393858/subreq] (2) init rewrite engine with requested uri /service/put/myfile.xml
XX.XXX.XXX.XXX - - [16/May/2010:06:33:40 +0000] [www.myserver.com/sid#7f378508aa30][rid#7f3785393858/subreq] (3) applying pattern '^/test/(.*)' to uri '/service/put/myfile.xml'
XX.XXX.XXX.XXX - - [16/May/2010:06:33:40 +0000] [www.myserver.com/sid#7f378508aa30][rid#7f3785393858/subreq] (1) pass through /service/put/myfile.xml
UPDATE 2 :
Apache configuration :
RewriteEngine on
RewriteLog "/etc/httpd/logs/rewrite.log"
RewriteLogLevel 9
RewriteCond %{REQUEST_METHOD} =PUT
RewriteRule ^/test/(.*) /$1 [PT]
RedirectMatch 301 ^/test/(.*)$ http://www.myserver.com/$1
AliasMatch ^/style/(.*)?$ "/var/www/test/www/style/$1"
AliasMatch ^/js/(.*)?$ "/var/www/test/www/js/$1"
AliasMatch ^/min/(.*)?$ "/var/www/test/www/min/$1"
AliasMatch ^/downloads/(.*)?$ "/var/www/test/www/downloads/$1"
AliasMatch ^/images/(.*)?$ "/var/www/test/www/images/$1"
AliasMatch ^/chart/(.*)?$ "/var/www/test/www/graphs/$1"
AliasMatch ^(/.*)?$ "/var/www/test/www/index.php$1"
<Directory "/var/www/test">
AllowOverride None
Allow from all
</Directory>
There is, with mod_rewrite:
RewriteEngine on
RewriteCond %{REQUEST_METHOD} =PUT
RewriteRule ^/test/(.*) /$1

Rewrite Url with apache2

I'm experimenting with CodeIgniter PHP framework, this framework works like:
http://localhost:7777/~dhalsim/ci/index.php/blog
So, I tried to remove index.php part from there. So far I do these:
make $config['index_page'] = "index.php"; to $config['index_page'] = "";
make $config['uri_protocol'] = "REQUEST_URI"; from $config['uri_protocol'] = "AUTO";
enable apache mod_rewrite by "a2enmod rewrite"
put a .htaccess file to /ci directory:
RewriteEngine on
RewriteBase /
RewriteCond %{REQUEST_URI} ^system.*
RewriteRule ^(.*)$ /index.php/$1 [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php?/$1 [L]
And of course restart apache server
Here is my apache logs with these configurations:
127.0.0.1 - - [17/Jul/2009:02:21:41 +0300] [localhost/sid#7f48e8ad2968][rid#7f48e8e634c8/initial] (3) [perdir /home/dhalsim/public_html/ci/] strip per-dir prefix: /home/dhalsim/public_html/ci/blog -> blog
127.0.0.1 - - [17/Jul/2009:02:21:41 +0300] [localhost/sid#7f48e8ad2968][rid#7f48e8e634c8/initial] (3) [perdir /home/dhalsim/public_html/ci/] applying pattern '^(.*)$' to uri 'blog'
127.0.0.1 - - [17/Jul/2009:02:21:41 +0300] [localhost/sid#7f48e8ad2968][rid#7f48e8e634c8/initial] (4) [perdir /home/dhalsim/public_html/ci/] RewriteCond: input='/~dhalsim/ci/blog' pattern='^system.*' => not-matched
127.0.0.1 - - [17/Jul/2009:02:21:41 +0300] [localhost/sid#7f48e8ad2968][rid#7f48e8e634c8/initial] (3) [perdir /home/dhalsim/public_html/ci/] strip per-dir prefix: /home/dhalsim/public_html/ci/blog -> blog
127.0.0.1 - - [17/Jul/2009:02:21:41 +0300] [localhost/sid#7f48e8ad2968][rid#7f48e8e634c8/initial] (3) [perdir /home/dhalsim/public_html/ci/] applying pattern '^(.*)$' to uri 'blog'
127.0.0.1 - - [17/Jul/2009:02:21:41 +0300] [localhost/sid#7f48e8ad2968][rid#7f48e8e634c8/initial] (4) [perdir /home/dhalsim/public_html/ci/] RewriteCond: input='/home/dhalsim/public_html/ci/blog' pattern='!-f' => matched
127.0.0.1 - - [17/Jul/2009:02:21:41 +0300] [localhost/sid#7f48e8ad2968][rid#7f48e8e634c8/initial] (4) [perdir /home/dhalsim/public_html/ci/] RewriteCond: input='/home/dhalsim/public_html/ci/blog' pattern='!-d' => matched
127.0.0.1 - - [17/Jul/2009:02:21:41 +0300] [localhost/sid#7f48e8ad2968][rid#7f48e8e634c8/initial] (2) [perdir /home/dhalsim/public_html/ci/] rewrite 'blog' -> 'index.php?/blog'
127.0.0.1 - - [17/Jul/2009:02:21:41 +0300] [localhost/sid#7f48e8ad2968][rid#7f48e8e634c8/initial] (3) split uri=index.php?/blog -> uri=index.php, args=/blog
127.0.0.1 - - [17/Jul/2009:02:21:41 +0300] [localhost/sid#7f48e8ad2968][rid#7f48e8e634c8/initial] (3) [perdir /home/dhalsim/public_html/ci/] add per-dir prefix: index.php -> /home/dhalsim/public_html/ci/index.php
127.0.0.1 - - [17/Jul/2009:02:21:41 +0300] [localhost/sid#7f48e8ad2968][rid#7f48e8e634c8/initial] (2) [perdir /home/dhalsim/public_html/ci/] trying to replace prefix /home/dhalsim/public_html/ci/ with /
127.0.0.1 - - [17/Jul/2009:02:21:41 +0300] [localhost/sid#7f48e8ad2968][rid#7f48e8e634c8/initial] (5) strip matching prefix: /home/dhalsim/public_html/ci/index.php -> index.php
127.0.0.1 - - [17/Jul/2009:02:21:41 +0300] [localhost/sid#7f48e8ad2968][rid#7f48e8e634c8/initial] (4) add subst prefix: index.php -> /index.php
127.0.0.1 - - [17/Jul/2009:02:21:41 +0300] [localhost/sid#7f48e8ad2968][rid#7f48e8e634c8/initial] (1) [perdir /home/dhalsim/public_html/ci/] internal redirect with /index.php [INTERNAL REDIRECT]
Here is the result in Firefox:
404 Not Found:
The requested URL /index.php was not found on this server.
So, what should I do (or where am I wrong) to get work these URLs?
http://localhost:7777/~dhalsim/ci/blog/ instead of http://localhost:7777/~dhalsim/ci/index.php/blog/
Here is how i resolve it:
RewriteEngine on
RewriteCond $1 !^(index\.php|images|flash|css|js|robots\.txt|downloads)
RewriteRule ^(.*)$ /index.php/$1 [L]
Then in the config.php file
/*
|--------------------------------------------------------------------------
| Base Site URL
|--------------------------------------------------------------------------
|
| URL to your CodeIgniter root. Typically this will be your base URL,
| WITH a trailing slash:
|
| http://example.com/
|
*/
$config['base_url'] = "http://localhost:7777/~dhalsim/ci/";
/*
|--------------------------------------------------------------------------
| Index File
|--------------------------------------------------------------------------
|
| Typically this will be your index.php file, unless you've renamed it to
| something else. If you are using mod_rewrite to remove the page set this
| variable so that it is blank.
|
*/
$config['index_page'] = "";
UPDATE
In the routes.php file:
//Point to default controller
$route['default_controller'] = "site/home"; //Set to your controller
// Point to the right controller
$routing_array = array(
'blog' => 'site/blog',
); // set to your blog controler
Use the following Rewrite Rule:
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} -s [OR]
RewriteCond %{REQUEST_FILENAME} -l [OR]
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^.*$ - [NC,L]
RewriteRule ^(.*)$ /index.php/$1 [NC,L]
In order for this to work you should setup your CodeIgniter app on a different port or use /etc/hosts to give it a simple Vhost (127.0.0.1 ci and http://ci:7777/ with Apache set to use the ci vhost.). Then you can set the base url to / and not worry about it. Otherwise you're going to have to deal with confusing directory issues and mod_rewrite.