如果url不包含某些字符串,则htaccess重定向 [英] htaccess redirect if url doesn't contain some string

查看:63
本文介绍了如果url不包含某些字符串,则htaccess重定向的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如果不包含#和admin,我想将所有传入请求重定向到另一个URL.我需要angular.js,但是我有/admin和php

I want to redirect all incoming requests to another url if it doesn't contain # and admin. I need it for angular.js, but I have /admin with php

例如:

http://example.com/link-to-article -> http://example.com/#/link-to-article

http://example.com/admin/ *不会重定向

推荐答案

您可以在 DOCUMENT_ROOT/.htaccess 文件中使用以下代码:

You can use this code in your DOCUMENT_ROOT/.htaccess file:

RewriteEngine On

RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule !^((admin|login)(/.*)?)?$ /#%{REQUEST_URI} [L,NC,NE,R=302]

还请记住,Web服务器不会在#之后添加URL,因为该问题仅在客户端解决.

Also remember that web server doesn't URL part after # as that is resolved only on client side.

  • RewriteCond%{REQUEST_FILENAME}!-f 跳过所有文件的此规则.
  • 使用会取消 RewriteRule 模式中的整个匹配
  • (((admin | login)(/.*)?)?是否与/admin//login/的任何内容匹配?空缺(着陆页)
  • 如果否定为true,则此规则会将其重定向到/#%{REQUEST_URI} ,其中%{REQUEST_URI} 代表原始URI.
  • RewriteCond %{REQUEST_FILENAME} !-f skips this rule for all files.
  • Using ! negates whole match in RewriteRule pattern
  • ((admin|login)(/.*)?)? matches anything that is /admin/ or /login/ OR emptry (landing page)
  • If negation is true then this rule redirects it to /#%{REQUEST_URI} where %{REQUEST_URI} represents original URI.

这篇关于如果url不包含某些字符串,则htaccess重定向的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆