3

現在、共有サーバーでSilex フレームワークを使用して Web サイトをホストしていますが、問題があります...

Silex は Symfony に似ており、/web/ サブフォルダーに app.php ファイルがあります。この Web サイトには、URL website.com/web/ からのみアクセスできます。共有サーバーなので仮想ホストを作成できないので、.htaccessファイルを使用するのが解決策だと思います...

website.com を website.com/web/ に自動的にリダイレクトできましたが、このオプションはあまり好きではありません。むしろ、website.com が直接 website.com/web/ を指すようにしたいのですが、.htaccess ファイルを使用してこれを行う方法がわかりません。私はこの問題を何時間も解決しようとしてきましたが、それは私を殺しています...

現時点では、このファイルを使用しています:

<IfModule mod_rewrite.c>
    Options -MultiViews
    
    RewriteEngine On
    RewriteBase /
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteRule ^ web/app.php [QSA,L]
</IfModule>

ただし、website.com から website.com/web にリダイレクトされるだけです。

とにかく、ルート URL が .htaccess ファイルを使用して /web フォルダーを直接指すようにすることはできますか?

どうもありがとうございました :)

4

2 に答える 2

6

http://example.comと入力するだけでhttp://example.com/subdirectoryにアクセスしたい場合は、これでうまくいくはずです。

# .htaccess main domain to subdirectory redirect 

RewriteEngine on 
# Change example.com to be your main domain. 
RewriteCond %{HTTP_HOST} ^(www.)?example.com$ 
# Change 'subdirectory' to be the directory you will use for your main domain. 
RewriteCond %{REQUEST_URI} !^/subdirectory/ 
# Don't change the following two lines. 
RewriteCond %{REQUEST_FILENAME} !-f 
RewriteCond %{REQUEST_FILENAME} !-d 
# Change 'subdirectory' to be the directory you will use for your main domain. 
RewriteRule ^(.*)$ /subdirectory/$1 
# Change example.com to be your main domain again. 
# Change 'subdirectory' to be the directory you will use for your main domain 
# followed by / then the main file for your site, index.php, index.html, etc. 
RewriteCond %{HTTP_HOST} ^(www.)?example.com$ 
RewriteRule ^(/)?$ subdirectory/ [L]
于 2016-05-01T21:19:43.733 に答える
1

このhtaccess構成を試してください:

DirectoryIndex web/app.php

<IfModule mod_rewrite.c>
    RewriteEngine On

    RewriteCond %{REQUEST_URI} !^/web/
    RewriteRule (.*) /web/$1
</IfModule>

<IfModule !mod_rewrite.c>
    <IfModule mod_alias.c>
        # When mod_rewrite is not available, we instruct a temporary redirect of
        # the start page to the front controller explicitly so that the website
        # and the generated links can still be used.
        RedirectMatch 302 ^/$ /web/app.php/
        # RedirectTemp cannot be used instead
    </IfModule>
</IfModule>
于 2013-11-29T07:31:53.567 に答える