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

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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]

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.