使得Web根文件夹的子文件夹的.htaccess? [英] Make web root folder a sub-folder with .htaccess?

查看:164
本文介绍了使得Web根文件夹的子文件夹的.htaccess?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我工作的一个pretty的复杂的工程,所以我想一起去的文件/文件夹结构,这是有道理的。

I'm working on a pretty complex project, so I'd like to go with a file/folder structure that makes sense.

文件夹/文件结构,我想拥有的是:

.htaccess
/php/
/assets/

我想有一个人会在访问网页:

/php/views/pages/

我不知道是否有可能只使用的.htaccess 设置 / PHP /视图/页作为在可视根,因此例如,当人们访问 http://mydomain.com/ 他们将观看的http:// mydomain.com/php/views/pages/index.php ,如果是这样,我怎么会去这样做呢?

I'm wondering if it's possible to use just .htaccess to set /php/views/pages as the "viewable root", so that for example, when people visit http://mydomain.com/ they'll be viewing http://mydomain.com/php/views/pages/index.php, and if so, how would I go about doing it?

此外,是否有可能规范化所有访问 / PHP /视图/页使用的.htaccess 和301重定向阻止多个环节被索引的搜索引擎?

Also, is it possible to canonicalize all access to /php/views/pages using .htaccess and a 301 redirect to stop multiple links being indexed in search engines?

推荐答案

的DocumentRoot 能仅在服务器和虚拟主机的configs使用,htaccess的它必须是

If you don't have access to your host configuration

DocumentRoot can only be used in server and virtual host configs, .htaccess it must be.

  1. 让我们在你的.htaccess添加指令

  1. Let's add directives in your .htaccess

RewriteEngine on

  • 我假设你想让请求/资产通过

  • I assume you want to let the requests to /assets go through

    #if a match for asset is found, do nothing
    RewriteRule ^assets/ - [L]
    

  • 如果一个请求尝试访问 / PHP /视图/页/ 直接重定向到它的规范版本

  • If a request tries to access /php/views/pages/ directly, redirect it to its canonical version

    RewriteCond %{THE_REQUEST} php/views/pages/
    RewriteRule ^php/views/pages/(.*) http://mydomain.com/$1 [R=301,L]
    

  • 和添加规则,一切映射到 / PHP /视图/页/

    RewriteCond %{REQUEST_URI} !php/views/pages/
    RewriteRule ^(.*)$ /php/views/pages/$1 [L]
    

  • 忘记.htaccess文件并使用它。一个示例配置可能看起来像

    If you have access to your host configuration

    Forget about .htaccess files and use it. A sample configuration could look like

    # ~base stands for your original DocumentRoot
    <VirtualHost *:80>
        DocumentRoot ~base/php/views/pages
        Alias /assets ~base/assets
    
        # other configuration parameters
    </VirtualHost>
    

    这篇关于使得Web根文件夹的子文件夹的.htaccess?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

    查看全文
    登录 关闭
    扫码关注1秒登录
    发送“验证码”获取 | 15天全站免登陆