2012-09-26 37 views
1

当前目录结构:的.htaccess - 从子目录重定向到根目录下不存在的文件

wwwpublic 
|+ spanish(language) 
|-- index.php 
|-- contact.php 
| 
|- index.php 
|- aboutus.php 
|- products.php 
|- contact.php 

在wwwpublic目录我在英语语言文件的根。由于网站也有西班牙语,我创建了一个名为'西班牙语'的独立目录。两个目录中的页面名称完全相同。

现在,西班牙语目录中的某些页面不存在,我需要将请求重定向到此类页面,以保留根文件夹并保留请求的文件名。

例子: 游客到访西班牙版本,还有的index.php开,然后他点击aboutus.php页面上(不要存在)西班牙目录内,然后重定向的.htaccess他到/root/aboutus.php

回答

1

尝试这样的事情在你的wwwpublic目录,最好在任何路由规则,你可以有:

RewriteEngine On 

# conditions to check that current request doesn't point to a valid resource 
RewriteCond %{REQUEST_FILENAME} !-f 
RewriteCond %{REQUEST_FILENAME} !-d 

# condition to check that request is for the /spanish/ directory 
RewriteCond %{REQUEST_URI} ^/spanish/(.+)$ 

# conditions to check if the /spanish/ is removed whether it would point to a valid resource 
RewriteCond %{DOCUMENT_ROOT}/%1 -f [OR] 
RewriteCond %{DOCUMENT_ROOT}/%1 -d 

# all conditions match, rewrite 
RewriteRule ^/?spanish/(.+)$ /$1 [L] 
相关问题