2

Our site, example.com, has a bunch of directories that used to have links like this:

example.com/product-line-1/index.php
example.com/product-line-2/index.php

Except, more often it would be:

example.com/product-line-1

OR

example.com/product-line-1/

I realize this is a common inconsistency/problem and we should've been more consistent when we built the site way back when.

However, we've picked a sytax to use and it no index.php, but use trailing slash

example.com/product-line-1/

We've normalized the links to always be example.com/product-line-1/ and have some htaccess to add the trailing slash when there isn't one.

The last bit is to 301 redirect any example.com/directory/index1.php to example.com/directory/ to preserve any link juice those links may have.

The htaccess is quite long with a ton of rules, but here is an excerpt of the more relevant ones:

## Enables gzip compression 
<IfModule mod_deflate.c> 
AddOutputFilterByType DEFLATE text/text text/html text/plain text/xml text/css application/x-javascript application/javascript 
SetEnvIfNoCase Request_URI .(?:exe|t?gz|zip|iso|tar|bz2|sit|rar|png|jpg|gif|jpeg|flv|swf)$ no-gzip dont-vary 
BrowserMatch ^Mozilla/4 gzip-only-text/html 
BrowserMatch ^Mozilla/4\.[0678] no-gzip 
BrowserMatch \bMSIE !no-gzip !gzip-only-text/html 
Header append Vary User-Agent env=!dont-vary 
</IfModule> 

## EXPIRES CACHING ##
<IfModule mod_expires.c>
ExpiresActive On
ExpiresByType image/jpg "access 1 year"
ExpiresByType image/jpeg "access 1 year"
ExpiresByType image/gif "access 1 year"
ExpiresByType image/png "access 1 year"
ExpiresByType text/css "access 1 month"
ExpiresByType text/html "access 1 month"
ExpiresByType application/pdf "access 1 month"
ExpiresByType text/x-javascript "access 1 month"
ExpiresByType application/x-shockwave-flash "access 1 month"
ExpiresByType image/x-icon "access 1 year"
ExpiresDefault "access 1 month"
</IfModule>
## EXPIRES CACHING ##


RewriteEngine on

DirectoryIndex index.php index.html index.htm
RewriteCond %{REQUEST_URI} !^/images/.*

Can I add a line of htaccess to 301 redirect the /index.php to /? Is this a bad idea since it would impact all directories?

Alternatively, I could add a line of htaccess for each /product-directory but this would be several hundred lines.

Thanks in advance!

1
  • How is your .htaccess ending with RewriteCond line? Commented Jul 14, 2014 at 7:07

1 Answer 1

2

Use this:

RewriteRule ^([^/]+)/index.php$ $1/ [L,R=301]
Sign up to request clarification or add additional context in comments.

2 Comments

Could you tweak this so it only redirects site.com/domain/index.php but not site.com/domain/domain/index.php?
@Kevin done :) this'll only redirect site.com/domain/index.php, and not site.com/index.php or site.com/domain/domain/index.php

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.