user2928505
user2928505

Reputation: 41

htaccess rewrite rule for url with querystring

I just did a huge makeover to a site and changed the framework. Because of that, the structure of urls changed. This is not a huge problem except for one url which is used a lot. I need to redirect user from the old address to the new one, and I just cannot figure out how to do that.

My rewrite rules currently are this:

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d

RewriteRule .* index.php/$0 [L]
RewriteRule ^/\?page/subpage/subsubpage.html\?param=(.*)$ /controller/function/$1 [L]

but it does not work, no redirect is happening.

Edit: Added the whole htaccess file! This currently gives me error 500 ( "Request exceeded the limit of 10 internal redirects due to probable configuration error.")

Options +FollowSymLinks

<IfModule mod_rewrite.c>
    RewriteEngine On
    RewriteBase /

    <Files .*>
        Order Deny,Allow
        Deny From All
    </Files>

    # Allow asset folders through
    RewriteRule ^(fuel/modules/(.+)?/assets/(.+)) - [L]
    RewriteRule ^(fuel/modules/(.+)?/tuki/(.+)) - [L]
    RewriteRule ^(fuel/modules/(.+)?/wiki/(.+)) - [L]
    
    

    # Protect application and system files from being viewed
    RewriteRule ^(fuel/install/.+|fuel/crons/.+|fuel/data_backup/.+|fuel/codeigniter/.+|fuel/modules/.+|fuel/application/.+) - [F,L]


    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    

    RewriteRule ^/\?page/subpage/subsubpage.html\?param=(.*)$ /controller/function/$1 [L]



    RewriteRule .* index.php/$0 [L]

    
    # Prevents access to dot files (.git, .htaccess) - security.
    RewriteCond %{SCRIPT_FILENAME} -d
    RewriteCond %{SCRIPT_FILENAME} -f
    RewriteRule "(^|/)\." - [F]
    
    
</IfModule>
Options -Indexes

Upvotes: 0

Views: 60

Answers (1)

RavinderSingh13
RavinderSingh13

Reputation: 133458

With your shown samples/attempts could you please try following. Please make sure you clear your browser cache before testing your URLs.

Options +FollowSymLinks
Options -Indexes
<IfModule mod_rewrite.c>
RewriteEngine ON
RewriteBase /

<Files .*>
Order Deny,Allow
Deny From All
</Files>

# Prevents access to dot files (.git, .htaccess) - security.
RewriteRule \.(git|htaccess) - [F]

# Allow asset folders through
RewriteRule ^fuel/modules/(assets|tuki|wiki) - [L]

# Protect application and system files from being viewed
RewriteRule ^fuel/(install|crons|data_backup|codeigniter|modules|application)/.+ - [F,L]

##Any non existing directory OR files whose URI srarts from page rule.
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^/\?page/subpage/subsubpage.html\?param=(.*)$ /controller/function/$1 [L]

####If any non existing directory OR file is requested then come here:
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^ index.php/$0 [L]
    
###New rule added by me here.....
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
ReWriteCond %{QUERY_STRING} .*=([^/[]*)/?$
RewriteRule ^ controller/function/%1 [L]  
</IfModule>

Upvotes: 1

Related Questions