HTAccess Rewrite Combo Meal (No Protocol, WWW, Add Trailing Slash, Etc)

Discussion in 'Apache' started by Komoti, Sep 21, 2011.

  1. #1
    Normally I have been able to copy paste the htaccess I needed but when I needed to do multiple modifications to a URL I can't seem to combine them or I end up with about 20 rules of which half are not necessary.

    This will be a template for a large number of websites I will be doing so I'm looking to get it perfect. All of the websites are CMS style(single entry point index.php - forgot what its called)

    This is the URL structure I'm looking for
    1. Base URL: example.com/ (Remove HTTP, WWW, index.php/html(if entered), Add Forward Slash)
    2. Top Level File: example.com/file (No Extensions, No Trailing Slash)
    3. Directory/File: example.com/directory/file
    4. Query String: example.com/directory/file?parameter=value

    Currently, I have the following which is what I'm looking to modify. As I'm not well versed with htaccess please point out any self defeating and redundant logic in what I do have. This allows me to access the above file structures so that part works at least.

    <IfModule mod_rewrite.c>
        RewriteEngine on
        # Do not rewrite AJAX request file
        RewriteRule ^(ajax.php) - [L]
        
        # Do not rewrite specific extensions
        RewriteCond %{REQUEST_URI} !\.(css|gif|ico|jpg|js|png|swf|txt)$
        
        # Do not rewrite existing files
        RewriteCond %{REQUEST_FILENAME} !-f
    
        # Do not rewrite existing directories.
        RewriteCond %{REQUEST_FILENAME} !-d
    	
        # Pray it works
        RewriteRule ^(.*)$ index.php?url=$1 [PT,L,QSA]
     </IfModule>
    Code (markup):
    Many thanks in advance for schooling me
     
    Komoti, Sep 21, 2011 IP