Jump to content

[.htaccess] Do No Rewrite A Specific Url


Jelte

Recommended Posts

Hello everybody,

 

This is one of my first times that i need to configure a .htacces file, so maybe is this a very simple question but I cant figure it out by myself :).

 

Situation:

 

I have a local site, that reachable under the URL: "framework.dev". But I need to configure a rewrite rule:

 

rewrite all the URL's to index.php, except the exact URL: 'framework.dev'.

 

example:

framework.dev/users //Rewrite this url to index.php
framework.dev/users/edit/1 //Rewrite this url to index.php
framework.dev/login //Rewrite this url to index.php
etc..
framework.dev //Do not rewrite

 

How do i formulate the correct .htacces rewrite rule?

 

Thank you for you time,

 

Greetings

 

Jelte

 

PS: I you know a good .htaccess tutorial please inform me :)

Link to comment
https://forums.phpfreaks.com/topic/270474-htaccess-do-no-rewrite-a-specific-url/
Share on other sites

Think of it in a slightly different way: don't rewrite /index.php, do rewrite everything else to /index.php. Note how the domain name doesn't matter (unless you want it to).

RewriteRule ^index.php - [L]
RewriteRule ^ index.php [L]

 

Or I think you might actually want to be rewriting anything that doesn't exist, that way images and CSS and those things will be served correctly.

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^ index.php [L]

Thanks for your comment,

 

I am afraid that is doesn't do the trick, i tested it and know framework.dev/test is unreachable (404 error)

 

But i think of another aproach, like you say the domain doenst matter, but we can check the request_uri. When i go to framework.dev the request_uri is: /.

and if i go to framework.dev/user the request_uri is: /user.

 

So i need the condiction for the following statement:

 

if request_uri is not equal to '/' then redirect to index else do no redirect.

 

Thanks for your help!

 

Greetings jelte.

I generally don't spell it out but maybe I should:

 

Did you include the RewriteEngine directive? It's necessary for absolutely anything having to do with mod_rewrite so I hardly ever bring it up (it's implied and I assume people have already done enough research to know that).

The complete example, with a small modification, is

RewriteEngine on
RewriteRule ^/?index.php - [L]
RewriteRule ^ index.php [L]

RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^ index.php [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.