0
votes

I used a generator to make my SEO friendly htaccess rewrite, here it is.

RewriteRule ^([^/]*)/([^/]*) /detail.php?type=$1&?id=$2 [L]

The output should be www.site.com/type/id

Now, the rewrite works and pages redirect fine, BUT the images on the site no longer show up, they're all broken... :( The URL for the images is right but seems it just doesn't want to load anymore, any help? Should there be another Rewrite rule to cancel out this one from doing other stuff? If so, what?

2

2 Answers

5
votes

Your existing rule could affect images. To prevent that, use a RewriteCond directive that will exlcude extensions for images etc. being affected by the rule You can add other extensions as necessary.

#if its not an image, css, js etc
RewriteCond %{REQUEST_URI} !\.(gif|jpg|png|css|js|etc)$ [NC]
RewriteRule ^([^/]*)/([^/]*) /detail.php?type=$1&?id=$2 [L]
2
votes

I'm not sure how your .htaccess looks like, but here is handy rules that I'm using for my projects, it's pretty simple and covers most of the problems:

<IfModule mod_rewrite.c>
    ############################################
    # Enable mod_rewrite
    RewriteEngine On
    RewriteBase /

    ############################################
    ## always send 404 on missing files in these folders
    RewriteCond %{REQUEST_URI} !^/(media|assets)/

    ############################################
    # never rewrite for existing files, directories and links
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteCond %{REQUEST_FILENAME} !-l

    RewriteRule .*$ index.php [L]
</IfModule>