1

如果网站 url 是www.domain.com/subfolder/sitecontent,那么我如何更新.htaccess下面的文件,以便所有请求都转到/subfolder/index.php而不是/index.php. 我知道我可以手动添加/subfolder/,但我需要它是动态的。可能吗?

基本上我打算在同一台服务器上的 2-3 个不同的 URL 上使用相同的 htaccess 和相同的文件集。例如一个是www.domain2.com/sitecontent(这里没有子文件夹)。所有这些 URL 都指向同一个站点。任何帮助将不胜感激。

这就是我当前.htaccess文件的样子。它位于/subfolder/.htaccessdomain1 或/第二个域示例。

<IfModule mod_rewrite.c>
    #http://codeigniter.com/wiki/mod_rewrite
    RewriteEngine On
    RewriteBase /

    #Removes access to the system folder by users.
    #Additionally this will allow you to create a System.php controller,
    #previously this would not have been possible.
    #'system' can be replaced if you have renamed your system folder.
    RewriteCond %{REQUEST_URI} ^system.*
    RewriteRule ^(.*)$ /index.php?/$1 [L]

    #When your application folder isn't in the system folder 
    #This snippet prevents user access to the application folder 
    #Rename 'application' to your applications folder name.
    RewriteCond %{REQUEST_URI} ^application.*
    RewriteRule ^(.*)$ /index.php?/$1 [L]

    #Checks to see if the user is attempting to access a valid file, 
    #such as an image or css document, if this isn't true it sends the 
    #request to index.php
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule ^(.*)$ index.php?/$1 [L]

</IfModule>

<IfModule !mod_rewrite.c>
    # If we don't have mod_rewrite installed, all 404's
    # can be sent to index.php, and everything works as normal.

    ErrorDocument 404 /index.php
</IfModule>

感谢您的帮助。

4

1 回答 1

1

不知道是否抓住了你需要的东西,但我认为你只需要附加文件夹名称,你可以试试这个:

<IfModule mod_rewrite.c>
    #http://codeigniter.com/wiki/mod_rewrite
    RewriteEngine On
    RewriteBase /subfolder

    #Removes access to the system folder by users.
    #Additionally this will allow you to create a System.php controller,
    #previously this would not have been possible.
    #'system' can be replaced if you have renamed your system folder.
    RewriteCond %{REQUEST_URI} ^system.*
    RewriteRule ^(.*)$ /subfolder/index.php?/$1 [L]

    #When your application folder isn't in the system folder 
    #This snippet prevents user access to the application folder 
    #Rename 'application' to your applications folder name.
    RewriteCond %{REQUEST_URI} ^application.*
    RewriteRule ^(.*)$ /subfolder/index.php?/$1 [L]

    #Checks to see if the user is attempting to access a valid file, 
    #such as an image or css document, if this isn't true it sends the 
    #request to index.php
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule ^(.*)$ /subfolder/index.php?/$1 [L]

</IfModule>

<IfModule !mod_rewrite.c>
    # If we don't have mod_rewrite installed, all 404's
    # can be sent to index.php, and everything works as normal.

    ErrorDocument 404 /index.php
</IfModule>
于 2012-11-20T13:09:57.077 回答