0
DirectoryIndex index.html index.php

# -- INIT
RewriteEngine on
RewriteBase /

# -- PRODUCTION
# RewriteCond %{HTTP_HOST} ^www.assist\.loc$ [NC]
# RewriteRule ^(.*)$ http://assist.loc/$1 [R=301,L]

# -- SEO index.html // index.php ??????????? DONT KNOW ????????
RewriteCond %{THE_REQUEST} ^.*/index\.(php|html)
RewriteRule .* / [R=301,L]

# -- HACKING
RewriteCond %{QUERY_STRING} base64_encode[^(]*\([^)]*\) [OR]
RewriteCond %{QUERY_STRING} (<|%3C)([^s]*s)+cript.*(>|%3E) [NC,OR]
RewriteCond %{QUERY_STRING} GLOBALS(=|\[|\%[0-9A-Z]{0,2}) [OR]
RewriteCond %{QUERY_STRING} _REQUEST(=|\[|\%[0-9A-Z]{0,2})
RewriteRule .* /index.php [F]

# -- DIRECTORIES
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI} ^(.+)/$
RewriteRule ^(.+)/$  /$1 [R=301,L]

# -- FILES
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule .* /index.php [L]

Hello, can something help me with writing my .htaccess file? I want add # -- SEO directive, for 301 redirect from index.php or index.html file to "/".

But now, i have redirecting from ALL routes to "/" or, cycling when redirecting from index.php or index.html.

Need to correct # -- SEO part.

gzhegow
  • 3
  • 1
  • 2
  • What happens to `%{REQUEST_FILENAME}` when the query is for `/`? I'm guessing that you rewrite `/index.php` to `/` with your SEO rule, and then the FILES rules test `%{REQUEST_FILENAME} !-f` and matches "not an existing file" and rewrites it back to `/index.php`... – TessellatingHeckler Nov 26 '15 at 21:38
  • So, i need for requesting "index.php", but my url need to be "/"... – gzhegow Nov 27 '15 at 02:59

1 Answers1

0

If you want to redirect any index.{anything} to the root path :

# -- DEFAULT DOCUMENT
DirectoryIndex index.html index.php

# -- INIT
RewriteEngine on

# -- REDIRECT ANY INDEX PAGE TO ROOT
RewriteCond %{Request_URI} /index\.
RewriteRule .* / [R=301]

# -- HACKING
RewriteCond %{QUERY_STRING} base64_encode[^(]*\([^)]*\) [OR]
RewriteCond %{QUERY_STRING} (<|%3C)([^s]*s)+cript.*(>|%3E) [NC,OR]
RewriteCond %{QUERY_STRING} GLOBALS(=|\[|\%[0-9A-Z]{0,2}) [OR]
RewriteCond %{QUERY_STRING} _REQUEST(=|\[|\%[0-9A-Z]{0,2})
RewriteRule .* /index.php [F]

# -- DIRECTORIES
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI} ^(.+)/$
RewriteRule ^(.+)/$  /$1 [R=301,L]

# -- REDIRECT REQUEST FOLDER TO /INDEX
RewriteCond %{DOCUMENT_ROOT}%{REQUEST_URI} !-f
RewriteCond %{DOCUMENT_ROOT}%{REQUEST_URI} !-d
RewriteRule .* /index.php [L]

for example :

  • www.test.com/index.php => will show www.test.com/
  • www.test.com/test/index.php => will show www.test.com/
  • www.test.com/any/folder/index.htm => will show www.test.com/

This will redirect any index.{anything} to his folder (if folder exist)

# -- REDIRECT ANY INDEX PAGE TO REQUEST FOLDER
RewriteCond %{Request_URI} /index\.
RewriteRule (.*)/index\. $1 [R=301]

And

# -- REDIRECT REQUEST FOLDER TO IT INDEX
RewriteCond %{DOCUMENT_ROOT}%{REQUEST_URI} !-f
RewriteCond %{DOCUMENT_ROOT}%{REQUEST_URI} !-d
RewriteRule (.*)/index\. %{DOCUMENT_ROOT}$1/index.php [L]

for example :

  • www.test.com/index.php => will show www.test.com/
  • www.test.com/test/index.php => will show www.test.com/test/
  • www.test.com/any/folder/index.htm => will show www.test.com/any/folder/
Froggiz
  • 3,043
  • 1
  • 19
  • 30