[英]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.