I want to rewrite URLs so when someone goes to:
url.com/directory1/directory2
He sees the URL in the browser address bar but actually the following URL is showing the text
url.com/index.php/directory1/directory2
So basically, the URL url.com/directory1/directory2
goes to url.com/index.php/directory1/directory2
How can I do that using .htaccess and/or mod_rewrite? What is the rewrite rule for that?
In your .htacces file use this:
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)/(.*)(\/?)$ /index.php/$1/$2 [NC,QSA,L]
OR in your httpd.conf
<VirtualHost *:80>
DocumentRoot "/var/www/"
ServerName www.url.com
ServerAlias www.url.com
<Directory /path/to/www/>
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)/(.*)(\/?)$ /index.php/$1/$2 [NC,QSA,L]
</Directory>
</VirtualHost>
If you use PHP:
$_SERVER['REQUEST_URI']
will have /asd/asd
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