【问题标题】:.htaccess rewrite: redirect all URLs except home URL and assets.htaccess 重写:重定向除主 URL 和资产之外的所有 URL
【发布时间】:2013-09-05 20:37:20
【问题描述】:

我希望除我的根 URL(//index.php)以及它使用的 JS/CSS 和图像资产之外的所有 URL 都重定向到另一个 URL。所有资产都包含在 /assets 目录中

这是我目前所拥有的,但它不起作用

RewriteEngine on

RewriteRule ^(.*)\.(?!js|css)([^.]*)$ $1\.php

RewriteCond %{REQUEST_URI} !^.assets$
RewriteCond %{REQUEST_URI} !/index.php$
RewriteCond %{REQUEST_URI} !/style.php$
RewriteCond %{REQUEST_URI} !/$

RewriteRule $ http://berlincallingny.eventbrite.com [R=302,L]

我需要的规则是:

  • 请勿重写任何包含“资产”的网址
  • 不要重写 index.php
  • 不要重写 style.php
  • 不要重写根 URL
  • 不要重写任何包含 .css 或 .js 的 URL

谢谢!

【问题讨论】:

  • 你的意思是它没有重定向吗?还是在不应该重定向的时候重定向?
  • 是的,关于所发生情况的更具描述性的信息会有所帮助。

标签: .htaccess redirect url-rewriting


【解决方案1】:

assets 目录的正则表达式在这里不正确:

RewriteCond %{REQUEST_URI} !^.assets$

用这个替换你的代码:

Options +FollowSymLinks -MultiViews
# Turn mod_rewrite on
RewriteEngine On
RewriteBase /

RewriteCond %{REQUEST_URI} !^/assets(/.*|)$ [NC]
RewriteCond %{REQUEST_URI} !/(index|style)\.php$ [NC]
RewriteRule ^.+$ / [R=302,L]

【讨论】:

    猜你喜欢
    • 2021-05-01
    • 2016-08-23
    • 2015-06-27
    • 2015-07-28
    • 2013-04-28
    • 1970-01-01
    • 2020-11-27
    • 2016-09-28
    • 2013-01-27
    相关资源
    最近更新 更多