Now, I have small problem.. I had my old page (removed now), so I want to redirect all incomings to new dir.. I have tried ; RewriteRule ^my-new-dir/$ my_old_page.php$1 [R=301,L] why is this not working ?
I think you have it backwards RewriteRule ^/$ new_dir [R,L] You might need to preface new_dir with a slash on some servers.
Thanks man.. it was backwards.. Funnything is all rest of the details in htaccess is backwards.. Or is it just 301 needs to be backwards ?? this worked, but witha slight problem.. RewriteRule ^my_old_file.php$ /my-new-dir/ [R=301,L] But this time any var after the old file comes up too.. if my_old_file.php?con=abc is requested then I get /my-new-dir/?con=abc I also added RewriteRule ^my_old_file.php?con=abc$ /my-new-dir/con-abc.html [R=301,L] I still get /my-new-dir/con-abc.html?con=abc How Can I truncate or avoid the vars ? Any ideas ??
I'm really not sure exactly what you want in every possible situation, but try this: RewriteRule ^(.*)$ /new_dir/$1 [R,L]
Well, let me put this way.. I have links like; my_old_file.php my_old_file.php?con=abc my_old_file.php?con=abc&def=def needs redirecting to; my_old_file.php ==> /my-new-dir/ (works fine) my_old_file.php?con=abc ==> /my-new-dir/con-abc.html (cant get it work, I get :/my-new-dir/con-abc.html?con=abc) my_old_file.php?con=abc&def=def ==> /my-new-dir/con-abc-def.html (cant get it work) Can you help me now ?
I got it to work ; RewriteCond %{HTTP_HOST} (www.)?mydomain.com RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d RewriteRule ^my_old_file.php(.*)$ my-new-dir/? [R=301,L] The trick was the ? between www and mydomain. Source Thanks though Bompa