I'm trying to build a url shortener, and I want to be able to take any characters immediately after the domain and have them passed as a variable url. So for example
would become
Here's what I have for mod_rewrite right now, but I keep getting a 400 Bad Request:
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*) index.php?url=$1 [L,QSA]
There are two main directive of this module: RewriteCond & RewriteRule . RewriteRule is used to rewrite the url as the name signifies if all the conditions defined in RewriteCond are matching. One or more RewriteCond can precede a RewriteRule directive.
There is no such Apache server variable HTTPS_HOST , only HTTP_HOST . If HTTPS_HOST is set on your server then it's specific to your server. The HTTP_HOST server variable contains the value of the Host HTTP request header (ie. the hostname), this is irrespective of the protocol used (HTTP or HTTPS).
Simply put, a redirect is a client-side request to have the web browser go to another URL. This means that the URL that you see in the browser will update to the new URL. A rewrite is a server-side rewrite of the URL before it's fully processed by IIS.
RewriteBase allows you to adjust the path that mod_rewrite automatically prefixes to the result of a RewriteRule . A rewrite within the context of . htaccess is done relative to the directory containing that . htaccess file.
Try replacing ^(.*)
with ^(.*)$
RewriteRule ^(.*)$ index.php?url=$1 [L,QSA]
Edit: Try replacing index.php
with /index.php
RewriteRule ^(.*)$ /index.php?url=$1 [L,QSA]
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With