Bsienn Bsienn - 7 months ago 22
PHP Question

need guide with mod_rewrite

I have a site on localhost xampp with virtualname mysite.com

I am trying to make the URLs simpler with the following code but its not working.

RewriteEngine On

RewriteRule ^$ index.php
RewriteRule ^home$ index.php


The above code works but its hard coded. So if I replace home with
^.*$
site assets gets missing. CSS etc doesn't work.

What I want is a rule that simply gives me everything after the domain so i can on backend use those and shows specific page.

mysite.com -gets-
mysite.com/ -gets- /
mysite.com/home -gets- home
mysite.com/products/abc -gets- products/abc
mysite.com/products/used/xyz -gets- products/used/xyz


please guide

Answer
Options +FollowSymLinks
RewriteEngine On
RewriteCond %{REQUEST_URI} !=/index.php
RewriteRule .* /index.php

Above code gives everything in the URL to index.php file.

If you want to use it for every URL except that is not ending with "png","jpg","css","js","gif" you can use :

Options +FollowSymLinks
RewriteEngine On
RewriteCond %{REQUEST_URI} !=/index.php
RewriteCond %{REQUEST_URI} !.*\.png$ [NC]
RewriteCond %{REQUEST_URI} !.*\.jpg$ [NC]
RewriteCond %{REQUEST_URI} !.*\.css$ [NC]
RewriteCond %{REQUEST_URI} !.*\.gif$ [NC]
RewriteCond %{REQUEST_URI} !.*\.js$ [NC]
RewriteRule .* /index.php