Dmitrij Holkin
Dmitrij Holkin

Reputation: 2055

Mod rewrite redirect direct access

  1. I need redirect all users which call index.html file.
  2. I need to use short link http://sites.com/111 but script takes files from fffolder/111.php
  3. I need to redirect users who is want direct access to http://sites.com/fffolder/111.php to index.html
Redirect 301 /index.html http://sites.com/ 
RewriteEngine On 
RewriteRule ^([a-zA-Z0-9_-]+)$ fffolder/$1.php 
RewriteRule ^([a-zA-Z0-9_-]+)/$ fffolder/$1.php  
RewriteCond %{REQUEST_FILENAME} !-f  
RewriteCond %{REQUEST_FILENAME} !-d
#If file not foun redirect to index 
RewriteRule .* index.html [PT]

#Redirect direct access to all php files in fffolder 
RewriteRule ^(.*)\.php$ index.html [R=301,L]

1 and 2 is working but 3 is not, how to write right syntax?

Upvotes: 1

Views: 58

Answers (1)

anubhava
anubhava

Reputation: 785098

You can use:

RewriteEngine On 

RewriteCond %{THE_REQUEST} /index\.html [NC]
RewriteRule ^(.*?)index\.html$ /$1 [L,R=301,NC]

#Redirect direct access to all php files in fffolder 
RewriteCond %{THE_REQUEST} /.+\.php [NC]
RewriteRule \.php$ /index.html [R=301,L,NC]

RewriteRule ^([\w-]+)/?$ fffolder/$1.php [L]

RewriteCond %{REQUEST_FILENAME} !-f  
RewriteCond %{REQUEST_FILENAME} !-d
#If file not foun redirect to index 
RewriteRule ^ index.html [L]

Upvotes: 1

Related Questions