使用 Silex、XAMPP 和多文件夹结构重写 htaccess/url

htaccess/url rewrite with Silex, XAMPP, and multifolder structure

提问人:user521990 提问时间:2/12/2019 最后编辑:user521990 更新时间:2/21/2019 访问量:270

问:

我尝试在 XAMPP 上为 Silex 应用程序正确设置 url 重写的多个先前线程,但仍然无法解决这个问题。这是我正在努力实现的目标。

我正在使用 XAMPP,这是我的 htdocs 文件夹的结构:

    - xampp 
        - htdocs
            - app1
            - app2
            - app3 <silex application>
                .htaccess file (outside of web folder)
                - web
                    index.php file

我目前可以做 http://localhost:50000/msk/web/cte。我的问题是我如何摆脱“网络”(即 http://localhost:50000/msk/cte)

我觉得我错过了一些小东西,但我无法弄清楚。

    <IfModule mod_rewrite.c>
       Options -MultiViews

       RewriteEngine On
       RewriteBase /msk/web/
       RewriteCond %{REQUEST_FILENAME} !-d
       RewriteCond %{REQUEST_FILENAME} !-f
       RewriteRule ^ index.php [QSA,L]
    </IfModule>

LoadModule rewrite_module modules/mod_rewrite.so 在我的配置中未注释。 我也没有使用虚拟主机。

谢谢

php mod-rewrite xampp silex

评论

0赞 Sergey Poltaranin 2/16/2019
可能重复使用 RewriteRule 删除部分 URL

答:

0赞 Ashu 2/18/2019 #1

您可以尝试:

<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /msk/web/
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/$1 [L]

RewriteRule ^cte/url-word$ cte/redirect-page [L]

</IfModule>
0赞 Saeed.Gh 2/21/2019 #2

在目录中使用以下内容:.htaccess/msk

Options +FollowSymLinks
IndexIgnore */*

<IfModule mod_rewrite.c>
RewriteEngine On

RewriteCond %{REQUEST_URI} !^/(web)
# ------- browser looks for them on base url -------- ex: /images/logo.png
RewriteRule ^css/(.*)$ web/css/$1 [L]
RewriteRule ^js/(.*)$ web/js/$1 [L]
RewriteRule ^images/(.*)$ web/images/$1 [L]
RewriteRule (.*) /web/$1

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /web/index.php
</IfModule>

并在您的目录中使用它.htaccess/msk/web

<IfModule mod_rewrite.c>
RewriteEngine On 

RewriteBase /

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d

RewriteRule . index.php
</IfModule>
2赞 Saclt7 2/21/2019 #3

试试这个

<IfModule mod_rewrite.c>
    RewriteEngine On
    RewriteBase /
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule ^(.*)$ index.php/$1 [L]
</IfModule>