Jump to content

[SOLVED] Help with .htaccess request directing


Jagarm

Recommended Posts

Hello everyone,

 

I am trying to write an MVC for my PHP web site, and I found this cool .htaccess code that directs all the request to index.php.

 

So for example if one enteres www.somesite.com/music.php this will act like this www.somesite.com/index.php?display=music.php.

 

This works great except I also have a CSS attached to the page and once the htaccess is enabled the css doesn't work.

 

How can I tell the .htaccess that if it is a css then just process it normally.

 

The following is the code:

RewriteEngine on

RewriteCond %(REQUEST_FILENAME) !-f
RewriteCond %(REQUEST_FILENAME) !-d

RewriteRule ^(.*)$ index.php?display=$1 [L,QSA]

 

Thanks all

Try:

 

RewriteEngine on

RewriteCond %{SCRIPT_FILENAME} !-f

RewriteCond %{SCRIPT_FILENAME} !-d

RewriteRule ^(.*) index.php?display=$1 [L,QSA]

 

 

That should forward anything that doesn't exist.

I think the REQUEST_FILENAME conds aren't working correctly.

I have the following .htaccess code that redirects all the request to PHP thus when doing berwari.net/movies it's like berwari.net/index.php?display=movies.

 

RewriteEngine on
RewriteCond %{SCRIPT_FILENAME} !-f
RewriteCond %{SCRIPT_FILENAME} !-d
RewriteRule ^(.*) index.php?display=$1 [L,QSA]

 

Now I am trying to make it as follow

berwari.net/movies/40 that means the following berwari.net/index.php?display=movies&n=40 that last one is optional it may sometimes be there whenever required.

 

I would appreciate if somebody could help me out with this.

 

Thanks

Then you'll specify a second rewrite rule.

RewriteEngine on
RewriteCond %{SCRIPT_FILENAME} !-f
RewriteCond %{SCRIPT_FILENAME} !-d

# matches berwari.net/movies/40
RewriteRule ^(.*)/([0-9]+) index.php?display=$1&n=$2 [L]

# matches berwari.net/movies
RewriteRule ^(.*) index.php?display=$1 [L]

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.