Search code examples
regexapache.htaccessmod-rewriteexpressionengine

Why does my url for my website have a ?. Already changed .htaccess


I am using ExpressionEngine as a CMS for my site. I've created an .htaccess with the following:

<IfModule mod_rewrite.c>
    RewriteEngine On
    RewriteBase /

    # Removes index.php from ExpressionEngine URLs
    RewriteCond %{THE_REQUEST} ^GET.*index\.php [NC]
    RewriteCond %{REQUEST_URI} !/system/.* [NC]
    RewriteRule (.*?)index\.php/*(.*) /$1$2 [R=301,NE,L]

    # Directs all EE web requests through the site index file
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule ^(.*)$ /index.php?/$1 [L]

    RewriteCond $1 !\.(gif|jpe?g|png)$ [NC]
    RewriteCond %{HTTP_HOST} ^www.gsmastersinc.com$ [NC]
    RewriteRule ^(.*)$ http://gsmastersinc.com/$1 [R=301,L]
</IfModule>

Why do all of my urls for my site have a ? in them? Ex. myurl/?/contact.

You can see what I'm talking about here: http://gsmastersinc.com, then click on any nav link. When hovering, it does not show the ?, only after clicking it.

I have to have the ? after the /index.php on the 13th line or the link is broken and I get a 404.

I've been searching for an answer all morning, but everything that comes up has to do with .NET or something similar.

Thanks


Solution

  • Change order of your rules:

    RewriteEngine On
    RewriteBase /
    
    RewriteCond $1 !\.(gif|jpe?g|png)$ [NC]
    RewriteCond %{HTTP_HOST} ^www.gsmastersinc.com$ [NC]
    RewriteRule ^(.*)$ http://gsmastersinc.com/$1 [R=301,L]
    # Removes index.php from ExpressionEngine URLs
    RewriteCond %{THE_REQUEST} ^GET.*index\.php [NC]
    RewriteCond %{REQUEST_URI} !/system/.* [NC]
    RewriteRule (.*?)index\.php/*(.*) /$1$2 [R=301,NE,L]
    
    # Directs all EE web requests through the site index file
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule ^(.*)$ /index.php?/$1 [L]
    

    In general keep your 301 rules before internal rewrite rules.