简体   繁体   English

Mod重写重定向直接访问

[英]Mod rewrite redirect direct access

  1. I need redirect all users which call index.html file. 我需要重定向所有调用index.html文件的用户。
  2. I need to use short link http://sites.com/111 but script takes files from fffolder/111.php 我需要使用短链接http://sites.com/111,但脚本会从fffolder / 111.php获取文件
  3. I need to redirect users who is want direct access to http://sites.com/fffolder/111.php to index.html 我需要将想要直接访问http://sites.com/fffolder/111.php的用户重定向到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? 1和2有效,但3无效,如何编写正确的语法?

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]

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM