简体   繁体   中英

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.

The problem Im having is passing 1234 to a page. I know how if it was out.php?q=1234 but I want it to be /out/1234

Does there need to be an index file within an /out directory that also has a htaccess to rewrite it?

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:

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM