【问题标题】:Removing specific path segments from url with .htaccess使用 .htaccess 从 url 中删除特定路径段
【发布时间】:2015-01-08 08:48:50
【问题描述】:

我当前的 url 结构如下所示:

Served from /var/www/app:

    /example.com/app/news
    /example.com/app/files
    /example.com/app/offers

Served from /var/www:

    /example.com/admin

结构有点奇怪,因为我只是通过在根文件夹中创建一个新的app 子目录将“应用程序”固定到当前的 CMS 上。我想要做的是提供应用程序文件,例如:

/example.com/news
/example.com/files
/example.com/offers

即只是从网址中删除app。但我显然仍然希望从原始根目录提供 /admin/ 路由。我该怎么办?

【问题讨论】:

  • 您自己尝试过什么?

标签: apache .htaccess url mod-rewrite


【解决方案1】:

你可以试试这个:

RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-d 
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_URI} !^/admin$
RewriteRule (.*) /app/$1 [L]

您可以在此处找到文档:http://httpd.apache.org/docs/2.4/mod/mod_rewrite.html

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-03-26
    • 2015-02-11
    • 1970-01-01
    • 1970-01-01
    • 2014-07-20
    相关资源
    最近更新 更多