Forum Moderators: phranque
I have recently been working on renovating a site. I have decided to use html extensions and the previous site used php
I am now to the point where I want to switch over the home page to the new home page via redirection as I don't want to lose anything within the search engines.
The issue is that I either get a redirection loop or the original index.php.
here is what I have in my htaccess - this is mainly allowing me to ue php within html extensions and keeping the url in the form I like (www.example.com)
AddType application/x-httpd-php htm html php
AddHandler application/x-httpd-php .htm .htmlRewriteEngine on
RewriteCond %{HTTP_HOST} ^example\.co.uk [NC]
RewriteRule ^(.*) http://www.example.co.uk/$1 [R=301]
RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /.*index\.php?\ HTTP/ [NC]
RewriteRule ^(.*)index.php?$ http://www.example.co.uk/$1 [R=301,L]
Redirect 301 /operation.php http://www.example.co.uk/
Can someone point me in the right direction of firstly being able to get the index.html to be the default page and how I can then redirect the old.
Thanks
The index redirect code you have is inefficient - there are better examples posted in many recent threads. In particular the .* part is very slow in use.
Additionally, never use Redirect in the same .htaccess file as you have used RewriteRule - use RewriteRule for all of the rules. For that one specific page you are redirecting, list that redirect first before all of the others, and ensure it has both the domain name and [R=301,L] within the rule.
As for your original description of what you want to do... Don't do it!
Redirect both '/index.php' and '/index.htm(l)' to '/' for root and again for all folders. That's a simple change to the code that you already have.
For root use '/' and for folders use '/folder/' in the links within your site. It is links that define URLs. Don't use the index file filename in the links on your site.
Do use the DirectoryIndex directive to specify the name of the file that will serve the content when a URL ending with a / is requested. When you swap the name there, from index.html to index.php, nothing needs to change in the URL.
Make sure that the redirects are listed in most-specific (single page) to least specific (non-www to www) order, and that they all have the full domain name and [R=301,L] within.
I will look for an alternate to the index as you suggested. I guess that I then do exactly the same for index.html to redirect to the route.
With regards to your section about not using redirect - if I wanted o make this rewriterule would it be something like this?
Redirect 301 /operation.php http://www.example.co.uk/ RewriteRule /operation.php http://www.example.co.uk[R=301] or is it more complex than this?
Also, a spaces is required before the flags, and you should always use the [L] flag on every rule unless you know the reason why you can't use it.
RewriteRule ^operation\.php$ http://www.example.co.uk [R=301,L]