【问题标题】:Eliminate folder name from Urls从 Urls 中删除文件夹名称
【发布时间】:2020-04-27 05:31:46
【问题描述】:

我有 WP 和 Laravel6 的结构。

my_site/
    .htaccess
    wp/
    laravel/.htaccess

和虚拟主机

<VirtualHost subdomain.local:777>
    DocumentRoot "c:\xampp\htdocs\my_site"
    ServerName subdomain.local
</VirtualHost>

由于我想从 WP 提供登录页面,我在 root .htaccess 中进行了一些更改以从 url 中删除 wp

RewriteEngine on
# remove wp from urls
RewriteCond %{HTTP_HOST} ^subdomain.local:777$
RewriteCond %{REQUEST_URI} !^/wp/
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ /wp/$1
RewriteCond %{HTTP_HOST} ^subdomain.local:777$
RewriteRule ^(/)?$ wp/index.php [L]

现在 subdomain.local:777 显示 wp 登录页面。

接下来我想从 laravel 提供的 url 中删除 laravel 文件夹,即:

subdomain.local:777/laravel/login to subdomain.local:777/login
subdomain.local:777/laravel/profile to subdomain.local:777/profile

等等..

为此,我在 laravel/.htaccess 中添加了以下内容,但它会使所有路由崩溃..

Options +FollowSymLinks -MultiViews
# Turn mod_rewrite on
RewriteEngine On
RewriteBase /
RewriteRule ^laravel/(.*)$ /$1 [L,NC,R]

有错误

Object not found!
The requested URL was not found on this server. If you entered the URL manually please check your spelling and try again.

If you think this is a server error, please contact the webmaster.

Error 404
subdomain.local
Apache/2.4.37 (Win32) OpenSSL/1.1.1 PHP/7.2.12

此外,我的 laravel/.htaccess 文件还配置 css/js/image/fonts 以像这样工作

Options -MultiViews -Indexes
RewriteEngine On

# Handle Authorization Header
RewriteCond %{HTTP:Authorization} .
RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}]

# Redirect Trailing Slashes If Not A Folder...
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI} (.+)/$
RewriteRule ^ %1 [L,R=301]

# Handle Front Controller...
RewriteCond %{REQUEST_URI} !(\.css|\.js|\.png|\.jpg|\.gif|robots\.txt|\.woff|\.woff2|\.ttf)$ [NC]
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ index.php [L]
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_URI} !^/public/
RewriteRule ^(css|js|images|google_map|image_compressor|admin-files|fontawesome-free|webfonts)/(.*)$ public/$1/$2 [L,NC]

或者我需要在 c:\xampp\apache\conf\httpd.conf 中编辑

【问题讨论】:

    标签: wordpress windows laravel .htaccess xampp


    【解决方案1】:

    最终通过根 .htaccess 中的位更改解决。这样 .htaccess 的最终版本现在是

    RewriteEngine on
    # remove wp from urls
    RewriteCond %{HTTP_HOST} ^subdomain.local:777$
    RewriteCond %{REQUEST_URI} !^/wp/
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule ^(.*)$ /wp/$1
    RewriteCond %{HTTP_HOST} ^subdomain.local:777$
    RewriteRule ^(/)?$ wp/index.php [L]
    
    # Rewrite Laravel Routes
    RewriteCond %{REQUEST_URI} !^/login [OR]
    RewriteCond %{REQUEST_URI} !^/profile
    RewriteRule ^(.*)$ laravel/public/$1 [L]
    

    【讨论】:

      猜你喜欢
      • 2014-04-22
      • 2020-03-19
      • 1970-01-01
      • 2023-04-10
      • 2014-10-28
      • 2019-07-18
      • 2016-04-13
      • 1970-01-01
      相关资源
      最近更新 更多