Page 1 of 1

Mod_rewrite issues

Posted: Tue Nov 06, 2007 2:42 am
by adrien
Hey guys,

I have searched and read many posts about mod_rewrite but have not found a solution for why I cannot get it running on my installation.  Perhaps someone can help me out.  I am not an advanced developer so I am hoping it is just a switch that I have not properly set.  I am getting an Object not found error when accessing links from the site.  FYI, my site is setup in C:\Projects\Second and the URL is http://localhost/Second (yes I realise that you cannot access it but I thought it might be helpfull when you read my config files).

This is my config.php

Code: Select all

#Show mod_rewrite URLs in the menu? You must enable 'use_hierarchy' for this to work for modules
$config['assume_mod_rewrite'] = true;

#Extension to use if you're using mod_rewrite for pretty URLs.
$config['page_extension'] = '';

#If you don't use mod_rewrite, then would you like to use the built-in
#pretty url mechanism?  This will not work with IIS and the {metadata} tag
#should be in all of your templates before enabling.
$config['internal_pretty_urls'] = false;

#If you're using the internal pretty url mechanism or mod_rewrite, would you like to
#show urls in their hierarchy?  (ex. http://www.mysite.com/parent/parent/childpage)
$config['use_hierarchy'] = true;

#If using none of the above options, what should we be using for the query string
#variable?  (ex. http://www.mysite.com/index.php?page=somecontent)
$config['query_var'] = 'page';
This is my htaccess -  I tried playing with the permissions a bit but nothing...

Code: Select all

#php_flag magic_quotes_gpc Off
#php_flag register_globals Off
#php_flag session.use_trans_sid Off

# Make sure you have Options FollowSymLinks
# and Allow on
RewriteEngine On

#Rewrites page.shtml as index.php?page
RewriteCond %{REQUEST_FILENAME} !-f [NC]
RewriteCond %{REQUEST_FILENAME} !-d [NC]
RewriteRule ^(.+)$ index.php?page=$1 [QSA]
This is my httpd.conf

Code: Select all

# First, we configure the "default" to be a very restrictive set of 
# features.  
#
<Directory />
    Options FollowSymLinks
    AllowOverride all
    Order deny,allow
    Deny from all
</Directory>

#
# Note that from this point forward you must specifically allow
# particular features to be enabled - so if something's not working as
# you might expect, make sure that you have specifically enabled it
# below.
#

#
# This should be changed to whatever you set DocumentRoot to.
#
<Directory "C:/Projects/">
    #
    # Possible values for the Options directive are "None", "All",
    # or any combination of:
    #   Indexes Includes FollowSymLinks SymLinksifOwnerMatch ExecCGI MultiViews
    #
    # Note that "MultiViews" must be named *explicitly* --- "Options All"
    # doesn't give it to you.
    #
    # The Options directive is both complicated and important.  Please see
    # http://httpd.apache.org/docs/2.2/mod/core.html#options
    # for more information.
    #
    Options Indexes FollowSymLinks Includes ExecCGI
   
    #
    # AllowOverride controls what directives may be placed in .htaccess files.
    # It can be "All", "None", or any combination of the keywords:
    #   Options FileInfo AuthConfig Limit
    #
    AllowOverride All

    #
    # Controls who can get stuff from this server.
    #
    Order allow,deny
    Allow from all

</Directory>

Re: Mod_rewrite issues

Posted: Tue Nov 06, 2007 3:05 am
by Lost
adrien wrote: FYI, my site is setup in C:\Projects\Second and the URL is http://localhost/Second (yes I realise that you cannot access it but I thought it might be helpfull when you read my config files).
Mod_rewrite does not work by default on Windows. I found this article that claims you can get it working under Windows:
http://www.astahost.com/info.php/apache ... 11623.html

I hope it helps...

Re: Mod_rewrite issues

Posted: Wed Nov 07, 2007 6:52 pm
by adrien
Thanks for the reply.  The install I was trying it on was my local so I tried making the changes to the server install (our beta site) and found that I was able to get the links working without the 500 errors but the stylesheets and images no longer worked.  Could this be caused by the fact that my website is not in the root of the server?  Seems odd?  My concern now is that I am unable to view the apache config files for this server since it is hosted.

Has anyone seen this before and if yes how can I solve it.  I do not mind contacting my ISP if I need to, I just don't want to sound like a babbling moron.

Adrien

Re: Mod_rewrite issues

Posted: Wed Nov 07, 2007 8:59 pm
by unknown
Hello,
FWIW I'm also struggling with this on a UNIX (not Linux) boxen.
I haven't run into this problem with other sites/CMS's (yet) and am fairly good with mod_rewrite voodoo.
So I thought I'd show you a 'couple of things I noticed in your setup that might be an issue.

Code: Select all

<Directory />
    Options FollowSymLinks
    AllowOverride all
    Order deny,allow
    Deny from all
</Directory>
might be better served as:

Code: Select all

<Directory />
        Options +FollowSymLinks
    AllowOverride all
    Order deny,allow
    Deny from all
</Directory>
note the added + (plus/addition sign)

Now, since you indicate that your CMS site isn't in the web root.
There are a 'couple of requirements to enlighten your web server as to how you want to
handle rewrite (present) your output.

Code: Select all

RewriteCond %{REQUEST_FILENAME} !-f [NC]
RewriteCond %{REQUEST_FILENAME} !-d [NC]
RewriteRule ^(.+)$ index.php?page=$1 [QSA]
is what you have now. But as you have it, it cannot work.
Two ways to fix this

1) Add a new line to the top of this:

Code: Select all

RewriteBase   /Projects/Second/
or

Code: Select all

RewriteBase   /Second/
Only ONE of the two are correct, and only ONE of them can be used.
Great! But which one?

To find out, we only need to one thing:
If the FILE path / leads to ANY web pages use:

Code: Select all

RewriteBase   /Projects/Second/
If FILE path / DOES NOT lead to ANY web pages, but /Projects/ DOES.
use:

Code: Select all

RewriteBase   /Second/
Otherwise the web root you are serving CMSMS would be out of it's OWN
directory, and nothing ahead of/before it. So RewriteBase would be /

2) The other option is to change the LAST line in the following:

Code: Select all

RewriteCond %{REQUEST_FILENAME} !-f [NC]
RewriteCond %{REQUEST_FILENAME} !-d [NC]
RewriteRule ^(.+)$ index.php?page=$1 [QSA]
to reflect the SAME FILE PATH scenario we just went through.
I'll suggest only one, given what you initially described in your post.
After having read all this, you will most probably be able to determine
the correct one.

Code: Select all

RewriteCond %{REQUEST_FILENAME} !-f [NC]
RewriteCond %{REQUEST_FILENAME} !-d [NC]
RewriteRule ^(.+)$ /Second/index.php?page=$1 [QSA]
Note the addition of /Second/ in the last line. This, or /Projects/Second/ will
be the probable options/needs in your situation.

Best Wishes.