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
Try it without using using RewriteCond
.
Check under Apache modules and make sure that rewrite-module is enabled. I had a similar issue and it was resolved by enabling the rewrite-module.
To rewrite all requests to /index.php
,you can use :
RewriteEngine on
RewriteCond %{REQUEST_URI} !^/index.php$
RewriteRule ^(.+)$ /index.php?url=$1 [NC,L]
The RewriteCondition RewriteCond %{REQUEST_URI} !^/index.php$
is important as it excludes the rewrite destination we are rewriting to and prevents infinite looping error.
ByTheWay don't forget to enable mod rewrite,in apache on ubuntu
sudo a2enmod rewrite
and then restart apache2
sudo /etc/init.d/apache2 restart
edit: it is an old question that helped me but I lost hours testing my apache2.conf file on one side and .htaccess file on the other side and still no light.
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]