So, I just managed to write some RewriteCond and RewriteRule for a custom site that I developed a while ago and as I’m a beginner in all of this, I was hopping that somebody will review my code and tell me if there’s anything to improve or if it is good as it is.
What I’m trying to achieve is to convert from /?mod=x to /x and from /?mod=x&type=y-z to /x/y-z
And here’s what I’ve done by now:
# Removes trailing slashes (prevents SEO duplicate content issues)
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.+)/$ $1 [L,R=301]
RewriteCond %{REQUEST_URI} /([a-z]+)/([a-z\-]+)$ [NC]
RewriteRule ^([^/]*)/([^/]*)$ /?mod=$1&tipo=$2 [NC,L]
RewriteCond %{REQUEST_URI} /([a-z]+)/?$ [NC]
RewriteRule ^([^/]*)$ /?mod=$1 [NC,L]
So, everything ok? Or, is there room for improvement?
You can combine these lines and remove the
RewriteCond:To:
Otherwise, this looks fine.
This rule directly conflicts with your other rules. They will rewrite each other because the target of one rule is the regex match of the other. Also, you need a
?at the end of your target to remove the actual query string. You need to match against the actual request: