简体   繁体   English

通过mod_rewrite忽略URL的特定部分

[英]Ignore a certain part of the URL via mod_rewrite

I have a Silex application and I get requests like this: https://.../dev/foo/bar and want to rewrite them to https://.../index.php/foo/bar 我有一个Silex应用程序,收到如下请求: https://.../dev/foo/bar并想将它们重写为https://.../index.php/foo/bar

Wheras "..." can be anything from "www.asd.com" to "localhost/~asd/folder". Wheras“ ...”可以是从“ www.asd.com”到“ localhost /〜asd / folder”的任何内容。

My .htaccess file is located at the web root, https://.../ 我的.htaccess文件位于Web根目录https://.../

This is the normal mod_rewrite setup I'm using: 这是我使用的正常mod_rewrite设置:

RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ index.php [QSA,L]

My naive try by setting the RewriteBase failed: 我通过设置RewriteBase的幼稚尝试失败了:

  RewriteEngine On
  RewriteBase /dev
  RewriteCond %{REQUEST_FILENAME} !-d
  RewriteCond %{REQUEST_FILENAME} !-f
  RewriteRule ^ index.php [QSA,L]

There I get the error 那里我得到了错误

Forbidden

You don't have permission to access /dev/index.php on this server.

Also just rewriting failed: 也只是改写失败:

RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^dev/(.*) index.php [L]

Strangely, it doesn't just skip the dev part, but it tries to access /dev/foo/bar instead of the desired /foo/bar. 奇怪的是,它不仅跳过了dev部分,而且尝试访问/ dev / foo / bar而不是所需的/ foo / bar。

Any clue? 有什么线索吗?

I found a solution for me by combining mod_alias and mod_rewrite like this, RewriteBase works now: 我通过将mod_alias和mod_rewrite像这样组合找到了解决方案, RewriteBase现在RewriteBase工作:

Alias /dev /app/web
<Directory /app/web>
    Options -MultiViews

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

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

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