Forum Moderators: phranque
I have working user friendly earls in place instead of dynamic urls, such as
[mysite.com...]
when I remove the www portion it gives me
[mysite.com...]
instead of taking me to
[mysite.com...]
I've been scratching what little hair I have left in trying to figure out what's wrong with the code but have come up firing blanks. I'd appreciate any thoughts on where I've gone wrong. thanks
category is an alpha only value taken from mysql
here's my original htaccess code
RewriteRule ^\-.html index.php
RewriteRule ^\dummy.html index.php
#redirect non www to www url
RewriteCond %{HTTP_HOST} ^mysite\.com$ [NC]
RewriteRule ^(.*)$ [mysite.com...] [R=301]
# rewrite user friendly url from dynamic url
RewriteRule ^([^-]*)-category$ /index.php?cat=$1 [L]
#rewrite requests to index.php to [mysite.com...]
RewriteCond %{THE_REQUEST} ^[A-Za-z]{3,9}\ /index\.php\ HTTP/
RewriteRule ^index\.php$ [mysite.com...] [R=301]
# redirect old dynamic urls to new friendly urls
RewriteCond %{THE_REQUEST} ^[A-Za-z]{3,9}\ /index\.php\?cat=([^\ ]*)\ HTTP/
RewriteRule ^index\.php$ [mysite.com...] [R=301]
Your 1 - 2 - 3 - 4 - 5 needs to be re-ordered as 4 - 5 - 2 - 1 - 3 and each rule needs [L] flag added.
Check the terminology in your comments. The lines with R=301,L are redirects not rewrites. Adjust the preceding comment accordingly.
I'm a bit confused with which rules you've numbered, have you marked them like this ..
1) RewriteRule ^\-.html index.php
2) RewriteRule ^\dummy.html index.php
#redirect non www to www url
3) RewriteCond %{HTTP_HOST} ^mysite\.com$ [NC]
RewriteRule ^(.*)$ [mysite.com...] [R=301]
# rewrite user friendly url from dynamic url
4) RewriteRule ^([^-]*)-category$ /index.php?cat=$1 [L]
#rewrite requests to index.php to [mysite.com...]
5) RewriteCond %{THE_REQUEST} ^[A-Za-z]{3,9}\ /index\.php\ HTTP/
RewriteRule ^index\.php$ [mysite.com...] [R=301]
# redirect old dynamic urls to new friendly urls
6) RewriteCond %{THE_REQUEST} ^[A-Za-z]{3,9}\ /index\.php\?cat=([^\ ]*)\ HTTP/
RewriteRule ^index\.php$ [mysite.com...] [R=301]
# redirect client requests for old dynamic urls to new friendly urls
RewriteCond %{THE_REQUEST} ^[A-Z]+\ /index\.php\?cat=([^\ ]*)\ HTTP/
RewriteRule ^index\.php$ http://www.example.com/%1-category? [R=301,L]
#
# redirect client requests for index.php to http://www.example.com/
RewriteCond %{THE_REQUEST} ^[A-Z]+\ /index\.php\ HTTP/
RewriteRule ^index\.php$ http://www.example.com/ [R=301,L]
#
# redirect non www hostname requests to www hostname
RewriteCond %{HTTP_HOST} ^example\.com [NC]
RewriteRule ^(.*)$ http://www.example.com/$1 [R=301,L]
#
RewriteRule ^-\.html$ index.php [L]
RewriteRule ^dummy\.html$ index.php [L]
#
# rewrite friendly url to dynamic filepath
RewriteRule ^([^-]+)-category$ index.php?cat=$1 [L]
Jim