Forum Moderators: phranque
I'm trying to get this code
# redirect client requests for old dynamic category urls to new friendly urls
RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /index\.php\?blockpage=([^\ ]*)&cat=([^\ ]*)\ HTTP/
RewriteRule ^index\.php$ http://www.example.com/%2-category-page%1?\.html [R=301,L]
to give me this result
http://www.example.com/category-page2.html
unfortunately it gives me a 404 page with a question mark in the url.
http://www.example.com/category-page2?.html
Is there any way of getting it to generate the url without the question mark. thanks
Here's the original htaccess code in it's entirety in case anything is conflicting.
# redirect client requests for old dynamic urls to new friendly urls (with pagination fix)
RewriteCond %{THE_REQUEST} ^[A-Z]+\ /index\.php\?cat=([^\ ]*)\ HTTP/
RewriteRule ^index\.php$ http://www.example.com/%1-category-page1.html? [R=301,L]
# redirect client requests for old dynamic category urls to new friendly urls
RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /index\.php\?blockpage=([^\ ]*)&cat=([^\ ]*)\ HTTP/
RewriteRule ^index\.php$ http://www.example.com/%2-category-page%1?\.html [R=301,L]
#redirect client requests for old dynamic category urls to new friendly urls (with pagination fix)
RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /index\.php\?cat=([^\ ]*)&blockpage=([^\ ]*)\ HTTP/
RewriteRule ^index\.php$ http://www.example.com/%1-category-page%2?\.html [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]
# I cant remember for the life of me why I added these
RewriteRule ^-\.html$ index.php [L]
RewriteRule ^dummy\.html$ index.php [L]
# rewrite friendly url to dynamic filepath for category pages (prevent dupe page 1 pagination)
RewriteRule ^([^-]+)-category-page1.html$ index.php?cat=$1 [L]
# rewrite friendly url to dynamic filepath for article pages
RewriteRule ^article-([0-9]+)-(.*)\.html$ index.php?article=$1&name=$2
# rewrite friendly url to dynamic filepath for main pages pages
RewriteRule ^([0-9]+)-(.*)\.html$ main-pages.php?pageid=$1&pagename=$2
# rewrite friendly url to dynamic filepath for category pages
RewriteRule ^([^-]+)-category-page([0-9]+).html$ index.php?cat=$1&blockpage=$2 [L]
If you don't see the question mark preceding "\.html", check your character-encoding settings, and use only a plain-text editor for working on Apache config code. Also, that backslash is not needed, since the substitution URL is not a regular-expressions pattern...
Jim
I had a wee problem with the query string appended onto the urls but after some digging found that adding a ? removes it.
I finally settled on these two working rules
RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /index\.php\?cat=([^\ ]*)&blockpage=([^\ ]*)\ HTTP/
RewriteRule ^index\.php$ http://www.example.com/%1-category-page%2.html? [R=301,L]
RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /index\.php\?blockpage=([^\ ]*)&cat=([^\ ]*)\ HTTP/
RewriteRule ^index\.php$ http://www.example.com/%2-category-page%1.html? [R=301,L]
thanks again guys