Jump to content

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 :)

Edited by Jelte
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]

Edited by requinix

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]

Edited by requinix
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.