简体   繁体   中英

Grabbing entire url as variable with htaccess

This is an image rotator that I'm trying to be able to manage completely through the url to avoid having to setup a user login system. With this system, the urls of the images to be added and removed from the list are passed through the url as a variable. When I type out the entire url: http://www.url.com/index.php?add=http://www.url2.com/images/image.png it works fine. When I try to do it with an htaccess file, http://www.url.com/add=http://www.url2.com/images/image.png , I get a 403.

Applicable .htaccess line:

RewriteRule ^add\=(.*)/? index.php?add=$1 [QSA]

This htaccess line works as long as I'm not trying to submit an entire url. Any ideas? If this isn't enough information just let me know.

-- Edit --

Added more information about the url that I'm trying to retreive

Try this rule:

RewriteEngine On

RewriteCond %{QUERY_STRING} ^$
RewriteCond %{THE_REQUEST} /add=(\S+) [NC]
RewriteRule ^ /index.php?add=%1 [QSA,L]

Comment from Ultimater and the solution:

The reason is because it's not a valid URL to begin with. You can't have two colons in the path. You can have them in the query string though but not in the path. http://localhost/add=http://localhost/ is an invalid URL. You can, however put a ? in front so it accepts the colon. Or simply omit the scheme. – Ultimater

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