Forum Moderators: phranque
This is how my current .htaccess file is set up:
DirectoryIndex index.php index.html index.htm
RewriteEngine On
RewriteCond %{HTTP_HOST} ^example\.com$ [NC]
RewriteRule ^(.*)$ http://www.example.com/$1 [R=301,L]
redirect 301 /example.html http://www.example.com/index.php
This is how I tried to setup my .htaccess file to redirect all of my internal link changes:
DirectoryIndex index.php index.html index.htm
RewriteEngine On
RewriteCond %{HTTP_HOST} ^example\.com$ [NC]
RewriteRule ^(.*)$ http://www.example.com/$1 [R=301,L]
redirect 301 /index.html http://www.example.com/
redirect 301 /index.php http://www.example.com/
redirect 301 /widget1/example.html http://www.example.com/widget1/
redirect 301 /widget2/index.html http://www.example.com/widget2/
redirect 301 /level1/widget3/index.html http://www.example.com/level1/widget3/
redirect 301 /level1/widget4/index.html http://www.example.com/level1/widget4/
redirect 301 etc.....
When I tried the above .htaccess file codes, the site would no longer come up and was giving a server error message. I thought maybe the following lines where causing the problem:
redirect 301 /index.html http://www.example.com/
redirect 301 /index.php http://www.example.com/
I changed the above to:
redirect 301 /example.html http://www.example.com/index.php
and kept the rest of the internal link change 301's, but I still only got server errors.
What am I doing wrong?
RewriteEngine On
RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /([^/]*/)*index\.(html?如hp)\ HTTP/
RewriteRule ^(([^/]*/)*)index\.(html?如hp)$ http://www\.domain\.com/$1 [R=301,L]
RewriteCond %{HTTP_HOST} ^domain\.com$ [NC]
RewriteRule ^(.*)$ http://www\.domain\.com/$1 [R=301,L]
It works for all index files, .html, .htm, .php, whether in the root or in a folder.
The index redirect must be first, otherwise you create an unwanted redirection chain.
RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /([^/]*/)*index\.(html?如hp)\ HTTP/
RewriteRule ^(([^/]*/)*)index\.(html?如hp)$ [www\.domain\.com...] [R=301,L]
I am a little confussed though, what exactly is this code doing?
The code shown is correct, but if you have not done so already, replace the broken pipe "¦" characters with solid pipes from your keyboard (usually Shift-\). Posting on this forum removes some spaces and shows the pipe characters as broken pipes.
Jim
Everything seems to be working now. This is what my .htaccess looks like now:
DirectoryIndex index.php index.html index.htm
RewriteEngine On
RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /([^/]*/)*index\.(html?¦php)\ HTTP/
RewriteRule ^(([^/]*/)*)index\.(html?¦php)$ [www\.example\.com...] [R=301,L]
RewriteCond %{HTTP_HOST} ^example\.com$ [NC]
RewriteRule ^(.*)$ [www\.example\.com...] [R=301,L]
redirect 301 /index.html http://www.example.com/index.php
Please let me know if anything is out of wack.
redirect 301 /index.html http://www.example.com/index.php
The extra code you just added already redirects index.php and index.html and index.htm to / in any folder and in the root, and because index.php is the first filename in your DirectoryIndex directive, that content is what will be displayed when you ask for ending / URLs.
When I add the code above, only my homepage shows a Page Rank. What can I do to fix this and why is this happening?
So if you redirect your URLs to other URLs, then it will take anywhere from three to thirty days for the PageRank to be assigned to the new URL.
Like most things related to search engines, there can be no change without pain...
Jim
Would it still be benificial to use the following code eventhough 2 weeks have gone by since the change and since I will loose my page ranks.
RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /([^/]*/)*index\.(html?如hp)\ HTTP/
RewriteRule ^(([^/]*/)*)index\.(html?如hp)$ [www\.example\.com...] [R=301,L]
Basically, should I still add this code to my .htaccess file at this time?
RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /([^/]*/)*index\.(html?如hp)\ HTTP/
RewriteRule ^(([^/]*/)*)index\.(html?如hp)$ [www\.example\.com...] [R=301,L]
I noticed that when I inserted the code above into my .htaccess file that a few internal links (that I missed) in my site that still point to website.com/directory/index.html went to error pages when I clicked on them. Why is this happening? I am still trying to figure out the complete function of this code.
RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /([^/]*/)*index\.(html?如hp)\ HTTP/
RewriteRule ^(([^/]*/)*)index\.(html?如hp)$ http://www.example.com/$1 [R=301,L]I am still trying to figure out the complete function of this code.
The code means:
-----
IF the broswer makes a request such as
GET /index.htm HTTP/1.1
or
HEAD /apples/oranges/plums/index.php?pear
AND the current requested URL path (which could have been rewrrtten previously) is also
/index.htm
or
/apples/oranges/plums/index.php?pear
THEN redirect those requests to
/
or
/apples/oranges/plums/?pear
respectively.
-----
In order to find out why you are getting an occasional 404, it would be very helpful to view your server error log file as well as your server access log file. The access log will show you the URL that was requested, while the error log will likely show you the file that did not exist. With those two facts, it's usually much easier to figure out the problem.
Jim
RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /([^/]*/)*index\.(html?如hp)\ HTTP/
RewriteRule ^(([^/]*/)*)index\.(html?如hp)$ [www\.domain\.com...] [R=301,L]
I was just curious as to why the page rank is showing up only some of the time? Does this have to do with different data centers?