RewriteCond %{REQUEST_URI} ^/new/
RewriteRule ^(.*)$ new.php?title=$1 [L,QSA]
im confused as to what this does....
what does the REQEUST_URI do ?
RewriteCond %{REQUEST_URI} ^/new/
RewriteRule ^(.*)$ new.php?title=$1 [L,QSA]
im confused as to what this does....
what does the REQEUST_URI do ?
If the URL begins with "/new/", it rewrites the URL to new.php, placing the old URL as the value for the "title" field.
"/new/Foo+Bar?bam=bug-AWWK!" becomes "new.php?title=/new/Foo+Bar&bam=bug-AWWK!" or (if the RewriteRule is in an .htaccess file) "new.php?title=new/Foo+Bar&bam=bug-AWWK!".
If (RewriteCond
) the requested URI starts with /new/
, the script new.php
is called (RewriteRule
). It will be passed the requested URI as the title
parameter, the query string (if any) will be preserved (the QSA
flag), and no further rules will be processed after this one (the L
flag).
i.e.
http://example.com/new/test.html
would call http://example.com/new.php?title=/new/test.html
http://example.com/new/test2.html?query=test3
would call http://example.com/new.php?title=/new/test2.html&query=test3
Basically it makes nice, pretty URLs.
It takes an URL like http:/www.example.org/new/foobar and in the background calls http://www.example.org/new.php?title=foobar.
REQUEST_URI is everything after the hostname. In the above example that's /new/foobar.
Your example can be explained as
RewriteCond %{REQUEST_URI} ^/new/
If the URL request is your hostname (REQUEST_URI) follow by new
folder...
RewriteRule ^(.*)$ new.php?title=$1 [L,QSA]
Then rewrite them as your hostname follow by provided string new.php?title=
and end with variables after /new/
in original URL request.
Example: URL request to:
http://yoursite.com/new/orange
server will interpret it as:
http://yoursite.com/new.php?title=orange
REQEUST_URI contains the current absolute URL path. So the rule will be applied on every request that’s URL path starts with /new/…
and rewrites/redirects it internally to the new.php file in the current directory (assuming that you didn’t change the base URL path with RewriteBase
).
So if you use this rule in the .htaccess file of
/
), a request of /new/foo/bar
would be rewritten/redirected to /new.php?title=new/foo/bar
./new/
, a request of /new/foo/bar
would be rewritten/redirected to /new/new.php?title=foo/bar
./new/foo
, the request would be rewritten/redirected to /new/foo/new.php?title=bar
.