Richard Williamson
Richard Williamson

Reputation: 154

Apache Rewrite rules not working as expected

I have two apache servers both have identical settings, I cloned the apache config files, and changed the ServerName part only. When I type mysite.com/somestuff it should rewrite to index.php it does it on my old server, but not my new. I have made sure the .htaccess is there when I do mysite.com/index.php/somestuff it works, but like my first site I need it to work with mysite.com/somestuff.

I am really banging my head against the wall here is my .htaccess and apache config file

#.htaccess file
<IfModule mod_rewrite.c>
    Options +FollowSymlinks
    RewriteEngine On

    RewriteCond %{ENV:REDIRECT_STATUS} ^$
    RewriteRule ^app\.php(/(.*)|$) %{CONTEXT_PREFIX}/$2 [R=301,L]
    RewriteCond %{REQUEST_FILENAME} -f
    RewriteRule .? - [L]

    RewriteCond %{REQUEST_URI}::$1 ^(/.+)(.+)::\2$
    RewriteRule ^(.*) - [E=BASE:%1]
    RewriteRule .? %{ENV:BASE}index.php/ [L]
</IfModule>

<IfModule !mod_rewrite.c>
    <IfModule mod_alias.c>
        RedirectMatch 302 ^/$ /index.php/
    </IfModule>
</IfModule>
<IfModule mod_headers.c>
    Header set Access-Control-Allow-Origin "*"
</IfModule>

Now for my apache config

<VirtualHost *:80>
        ServerAdmin [email protected]
        ServerName mysite.com
        DocumentRoot /home/richardw/www/halogen/web
        <Directory />
                Options FollowSymLinks
                AllowOverride All
        </Directory>
        <Directory /home/richardw/www/halogen/web/>
                Options Indexes FollowSymLinks MultiViews
                AllowOverride All
                Order allow,deny
                allow from all
        </Directory>

        ErrorLog ${APACHE_LOG_DIR}/error.log

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

        CustomLog ${APACHE_LOG_DIR}/access.log combined
</VirtualHost>

My apologizes if this is a repost, but I've been searching all over and i'm about to lose it.

Upvotes: 1

Views: 970

Answers (2)

Jon Lin
Jon Lin

Reputation: 143886

When you go to http://mysite.com/, are you redirected to http://mysite.com/index.php/?

If this is happening, that means mod_rewrite is not loaded in your new server. You need to make sure it's loaded in your apache's server config file. See this answer for some instructions on how that works for apache.

The reason why the redirect is working is because of this container:

<IfModule !mod_rewrite.c>
    <IfModule mod_alias.c>
        RedirectMatch 302 ^/$ /index.php/
    </IfModule>
</IfModule>

This essentially says "if mod_rewrite is not loaded", then if mod_alias is loaded, it redirects the root request to /index.php/. So if the redirect is happening, mod_rewrite is not loaded.

Upvotes: 2

Have you try to comment or remove this line
Options +FollowSymlinks
in your .htaccess?

Upvotes: 0

Related Questions