简体   繁体   English

仅当传入URL包含特定字符串时,如何才能重定向它?

[英]How can I redirect an incoming URL only if it contains a certain string?

We currently have our company's image hosting site on our own server for the sake of performance. 为了提高性能,我们目前在自己的服务器上拥有公司的图像托管站点。 We want to separate the front end of the site (generic pages) from the database-driven backend (where all users upload and view images) so that the front end can be hosted off-site and be enhanced for SEO while the backend stays local on our dedicated server for better performance. 我们希望将站点的前端(通用页面)与数据库驱动的后端(所有用户都在其中上传和查看图像)分开,以便可以将后端托管在非现场并针对SEO进行增强,同时后端保持本地状态在我们专用的服务器上以获得更好的性能。

With that in mind, I plan to point the main domain to the offsite hosted pages. 考虑到这一点,我计划将主域指向非现场托管页面。 Currently our clients have urls pointing to jobs on our server which we cannot change. 当前,我们的客户有指向我们服务器上无法更改的作业的url。 So, we want to be able to redirect any urls that have a certain string (referring to the backend) to our local server's static IP address. 因此,我们希望能够将任何具有特定字符串(指后端)的url重定向到我们本地服务器的静态IP地址。

Example: 例:

  • www.domain.com/aboutus/ ← Does not contain target string, so no change www.domain.com/aboutus/不包含目标字符串,因此没有更改

  • www.domain.com/TARGETSTRING/something/something/ ← Has target string, so it will point to our static local IP address, ie http://294.34.21.5/TARGETSTRING/something/something www.domain.com/TARGETSTRING/something/something/具有目标字符串,因此它将指向我们的静态本地IP地址,即http://294.34.21.5/TARGETSTRING/something/something

One other note: Currently the whole site is running on ColdFusion on IIS. 另一个注意事项:目前,整个站点都在IIS的ColdFusion上运行。 With the new setup, the backend (local server) will stay the same, but the front end will be in Wordpress. 使用新设置,后端(本地服务器)将保持不变,但前端将位于Wordpress中。 So I imagine that the htaccess file may come into play, but not with the usual RewriteRule mod. 因此,我认为htaccess文件可能会起作用,但不能使用通常的RewriteRule mod。

You should be able to handle this in PHP by checking the $_SERVER var that is most applicable. 您应该能够通过检查最适用的$ _SERVER var在PHP中进行处理。

http://php.net/manual/en/reserved.variables.server.php http://php.net/manual/en/reserved.variables.server.php

You can then set a conditional and, if (say a regex pattern match is true) then perform a server-side redirect with location . 然后,您可以设置条件,如果(例如,正则表达式模式匹配为true),则使用location执行服务器端重定向。

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

相关问题 如何使用正则表达式检查字符串仅包含某些允许的字符? - How can I check with a regex that a string contains only certain allowed characters? 如何重定向/重写包含特定字符串的所有URL? - How can I redirect/ rewrite all urls that contain a certain string? 301 redirec文件夹 - 我如何才能重定向精确的网址 - 301 redirec folder - how i can redirect only exact url 我怎样才能只为某些页面重写我的网址 - how can i rewrite my url for only certain pages 如何检查字符串是否仅包含英文字母? - How can I check whether is a string contains only English letters? 如果 URL 包含特定字符串,如何隐藏/显示某些元素/div? - How do I hide/show certain elements/divs if URL contains a specific string? 如果URL包含特定字符串,如何更改创世Wordpress上的徽标和菜单? - How to change logo and menu on genesis Wordpress if URL contains a certain string? PHP-如何编写正则表达式以检查字符串仅包含某些字符? - PHP - How to write a regex to check that a string only contains certain characters? 如果网址仅包含字母或数字,则重定向 - Redirect if url ONLY contains letters or numbers 如果使用PHP包含某字符串,如何从文件中删除一行? - How can I delete a line from a file if it contains a certain string using PHP?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM