I am trying to redirect a series of php address to a single absolute address. Something like: mysite.com/cookbooks/free.php?in=us&asin=B0000645E8 to mysite.com/ My .htaccess is: RedirectMatch /cookbooks/(.*)\.php$ mysite.com/index.html (I took the http://www. out because I can't post live links) Which redirect to "mysite.com/index.html?in=us&asin=B0000645E8. How do I get rid of the training code in the URL? Thanks. FB
I send it to a page called redirect.php which then uses a simple on page 301 redirect to send it to the correct location. Seems like a strange way around it but at the time it was quicker than trying to figure out the solution.
Would that have the same issus as my rewrite -- where the end of the link is pass through to the redirect destination? FB
This method (mod_alias) is not suitable for such redirects. Redirect or RedirectMatch (directives provided by mod_alias) are used to subsitute the host and initial directories (matched). It automatically appends the rest of the path and the query string to the target url. The correct method is to use mod_rewite. Use this code instead: RewriteEngine On RewriteRule ^/cookbooks/.*\.php.*$ http://www.mysite.com/index.html Code (markup): It would not append anything to the target url. The matching regexp can be improved. I hope that helps. PS: You can post urls (not live links though) as I did.
I just cannot get this to work. Any help would be appreciated. Here are my three rewrites in .htaccess. The other two see to work. Help! FB Code: RewriteEngine On RewriteRule ^/cookbooks/.*\.php.*$ http://www.mysite.com/index.html # REWRITE RULES Options +SymlinksIfOwnerMatch -Indexes <IfModule mod_rewrite.c> RewriteEngine on RewriteBase / RewriteCond %{HTTP_HOST} !^www\.mysite\.com [NC] RewriteRule ^(.*)$ http://www.mysite.com/$1 [R=301,L] </IfModule> RewriteEngine On RewriteRule ^((urllist|sitemap_).*\.(xml|txt)(\.gz)?)$ forum/vbseo_sitemap/vbseo_getsitemap.php?sitemap=$1 [L]
If you set a RewriteBase, the match pattern should not start with a slash (/). Perhaps, you dont know much about url rewriting. The line of code I posted above needs some rewrite flags appended to it ([L]) if there are more rules there. Here is your full htaccess code with external redirect for /cookbook/*.php, tested and working. Just copy and paste without any modification. Options +SymlinksIfOwnerMatch -Indexes # REWRITE RULES <IfModule mod_rewrite.c> RewriteEngine on RewriteBase / RewriteCond %{HTTP_HOST} !^www\.mysite\.com [NC] RewriteRule ^(.*)$ http://www.mysite.com/$1 [R=301,L] RewriteRule ^cookbooks/.*\.php http://www.mysite.com/index.html? [R=301,L] RewriteRule ^((urllist|sitemap_).*\.(xml|txt)(\.gz)?)$ forum/vbseo_sitemap/vbseo_getsitemap.php?sitemap=$1 [L] </IfModule> Code (markup): Dont remove the trailing question mark (?) for the substitution url (http://www.mysite.com/index.html?), it does the trick for stipping out any query string if there is one. I forgot to include this in my post above. Cheers! - Zulu