简体   繁体   English

将example.com/out/1234重定向到另一个URL

[英]Redirect example.com/out/1234 to another URL

I know theres a lot of posts about redirects but this is a little different (I think). 我知道有很多关于重定向的文章,但这有些不同(我认为)。

Basically I want my outlinks to be example.com/out/1234 and I want them to go to a php that looks up the URL 1234 if referenced to in MySQL and the php header redirect to that URL. 基本上,我希望我的出站地址为example.com/out/1234,并且希望他们转到一个在MySQL中引用该URL的php(如果在MySQL中被引用),并且php标头重定向到该URL。

The problem Im having is passing 1234 to a page. 我遇到的问题是将1234传递给页面。 I know how if it was out.php?q=1234 but I want it to be /out/1234 我知道它是否为out.php?q = 1234,但我希望它为/ out / 1234

Does there need to be an index file within an /out directory that also has a htaccess to rewrite it? / out目录中是否需要一个索引文件,该文件也具有htaccess重写它?

If so, any ideas what the regex need to be to do this? 如果是这样,有什么想法需要进行正则表达式处理吗? I have seen a few sites doing this and I cant work it out. 我看到一些网站正在这样做,但我无法解决。

htaccess file in your document root, you can try adding: 您的文档根目录中的htaccess文件,您可以尝试添加:

RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^/?out/(.*)$ /out.php?q=$1 [L]

Replace the /out.php with whereever your php script for handling the URL is /out.php替换为用于处理URL的任何php脚本

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

相关问题 使用example.com/blog?p=1234将URL重定向到wordpress默认URL(example.com/blog/actual-url-of-post)在Safari中不起作用 - Redirect URL's with example.com/blog?p=1234 to wordpress default URL (example.com/blog/actual-url-of-post) doesn't work in Safari 将example.com重定向到example.com/blog - Redirect example.com to example.com/blog Apache 2阻止网址,例如example.com/?admin - Apache 2 block url such as example.com/?admin 将www.domain.com/example.com重定向到example.com - redirect www.domain.com/example.com to example.com 为什么 htaccess 重定向到 https://example.com/index.php 而不是特定的子网址? - why htaccess redirect to https://example.com/index.php instead the specific sub-url? http://example.com/fruits/apple我想重定向到http://example.com/pen/apple - http://example.com/fruits/apple I want to redirect to http://example.com/pen/apple 使用,htaccess将example.com?id=12重定向到example.com/index.php?id=12 - using ,htaccess redirect example.com?id=12 to example.com/index.php?id=12 如何让所有 example.com 页面重定向到 example.com/smth - How can I make all example.com pages redirect to example.com/smth 是否可以将 example.com/index.php?page=abc 重定向到 example.com/abc? - Is it possible to redirect the example.com/index.php?page=abc to example.com/abc? 如何将example.com/forum/index.php重定向到example.com/forum/ - How to redirect example.com/forum/index.php to example.com/forum/
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM