What would the code be to have a 301 redirect mydomain.com to www.mydomain.com Also I have an HTACCESS setup, would I add the code setup for wordpress permalinks. So would I add this new code in the same <IfModule mod_rewrite.c> </IfModule> or set it up under its own <IfModule mod_rewrite.c> </IfModule>?
Try this: <IfModule mod_rewrite.c> RewriteEngine On RewriteBase / RewriteCond %{HTTP_HOST} !^www\.domain\.com [NC] RewriteRule ^(.*) http://www.domain.com/$1 [L,R=301] </IfModule> Code (markup):
<IfModule mod_rewrite.c> </IfModule> Code (markup): Why do you need these two at all? Don't you know if mod_rewrite is enabled on your server?
It can be useful if you're writing a product to be deployed on many servers that you don't have control over.
If the rewrite rules are only for your server and you know you have mod rewrite enabled, no. It does exactly what it says - anything inside the ifmodule tags will only be read if that particular module is enabled. If you try and rewrite without having mod_rewrite enabled, you'll run into problems so if you're distributing your software it's a good idea to use it. If you're just coding your own project on your own server, it's probably unnecessary.
It's entirely unnecessary. I've never used it. That's why I asked about its purpose. You might need to add one line though: Options +FollowSymLinks RewriteEngine On RewriteBase / RewriteCond %{HTTP_HOST} !^www\.domain\.com [NC] RewriteRule ^(.*) http://www.domain.com/$1 [L,R=301] Code (markup):
Not at all - for the sake of two lines, it's simply a best practice to avoid causing internal server errors. Even if it is only for your server, it's normal to code with portability in mind.
hmmmm I tried to do this a whileback and came up with this code: RewriteCond %{HTTP_HOST} !^www\..* RewriteCond %{HTTP_HOST} !^$ RewriteCond %{HTTP_HOST} ^([^.]*)\.(com\.au) RewriteRule ^.*$ http://www.%1.%2%{REQUEST_URI} [R=permanent,L] Code (markup): It works, but maybe it doesn't do a 301. Should I change this part: [R=permanent,L] to: [R=301,L] Sorry to hijack the thread, but it's related to the initial question
Sir i have a very simple question i have a website and its in php i have use the redirect engine to show extension as html insteade of php but in my site all links and stuff r in php and its now hard to chaneg each link to html so can u let meknow how to do that in htaccess here is my htaccess code Options +FollowSymLinks RewriteEngine On RewriteRule ^([^.]+).html$ /$1.php [QSA,L] its work fine if some one type my sitenae.com/index.php works and mysitename.com/index.html works fine but i want when a type .php so it iwll automatically redirect to respective html file please help me asap