Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

mod_rewrite URLs

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?

like image 359
Chris Hansen Avatar asked Oct 10 '22 00:10

Chris Hansen


1 Answers

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

like image 140
Book Of Zeus Avatar answered Oct 18 '22 11:10

Book Of Zeus