简体   繁体   English

如何从我的 URL 中删除“/web”?

[英]How do I remove the “/web” from my URL?

I am using the crud-admin-generator ( http://crud-admin-generator.com/ ) to generate a quick backend for my web app, which is based on the silex framework.我正在使用 crud-admin-generator ( http://crud-admin-generator.com/ ) 为我的 web 应用程序生成一个快速后端,它基于 silex 框架。

My app structure is:我的应用程序结构是:

MyApp
  ->index.php
  ->some_other_files
  ->...
  ->admin (the crud-admin-generator git clone)
      ->gen
      ->src
      ->vendor
      ->web
         ->controllers
         ->resources
         ->views

1) When I access the admin I currently need to use http://localhost/MyApp/admin/web . 1)当我访问管理员时,我目前需要使用http://localhost/MyApp/admin/web I want to remove the /web part.我想删除/web部件。 I tried creating a custom htaccess in the admin folder with:我尝试使用以下命令在admin文件夹中创建自定义htaccess

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

But I keep getting an error: The requested URL /web/index.php was not found on this server.但是我不断收到错误消息: The requested URL /web/index.php was not found on this server.

2) The generated admin panel uses the silex framework, is there a easy way for me to use the doctrine component or the framework itself for my frontend as well (files outside the admin folder)? 2) 生成的管理面板使用 silex 框架,是否有一种简单的方法可以让我在前端(管理文件夹外的文件)中使用学说组件或框架本身? Would I need to manually change the routing paths of all the generated admin files?我是否需要手动更改所有生成的管理文件的路由路径? Sorry if I sound confused.对不起,如果我听起来很困惑。

Keep your /MyApp/admin/.htaccess like this:保持你的/MyApp/admin/.htaccess像这样:

<IfModule mod_rewrite.c>
    Options -MultiViews    
    RewriteEngine On
    RewriteBase /MyApp/admin/

    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteRule ^((?!web/).*)$ web/$1 [NC,L]
</IfModule>
<IfModule mod_rewrite.c>
    Options -MultiViews    
    RewriteEngine On
    RewriteBase /mekaturk1/admin/

    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteRule ^((?!web/).*)$ web/$1 [NC,L,R]
</IfModule>

-> web/$1 [NC,L,R] is Important R -> web/$1 [NC,L,R] 是重要的R

After hours and more hours in front of the computer googleing for the propper solution, finally i found the one that worked for me:在电脑前搜索合适的解决方案几个小时后,我终于找到了对我有用的解决方案:

Step 1: Enable your Apache rewrite_module第 1 步:启用您的 Apache rewrite_module

Step 2: Edit your .htaccess file to look like the following lines第 2 步:编辑您的 .htaccess 文件,使其看起来像以下几行

Options -MultiViews


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

I hope it works.我希望它有效。

because some reason, it will be variant to solve this problem, in my case i use this code因为某种原因,解决这个问题会有所不同,在我的情况下,我使用这个代码

<IfModule mod_rewrite.c>
    Options -MultiViews    
    RewriteEngine On
    RewriteBase /MyApp/admin/

    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteRule ^((?!web/).*)$ web/index.php [NC,L,R]
</IfModule>

sorry, my english so bad对不起,我的英语太糟糕了

Try尝试

RewriteRule ^(.*)/web$ /$1 [L,R=301]

These should find the word "web" from the end of the url, I have tested.这些应该从 url 的末尾找到“web”这个词,我已经测试过了。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM