0

I want:
domain.com/example
to target:
domain.com/folder/example.cshtml

Can anyone help me with the rewrite rule for it?



Every suggestion is much appreciated :)


I have edited the question so that it actually focuses on what is important.

Nikita
  • 609
  • 2
  • 7
  • 18
  • Do you get a 404 when hitting `domain.com/example.cshtml` from your browser? – cheesemacfly Feb 24 '13 at 17:18
  • @cheesemacfly Yes, though I was thinking in the wrong direction, vice-versa to be precise. The code in the question doesn't make sense though. – Nikita Feb 24 '13 at 17:28
  • Yes, I guess you should first fix your 404 error then :) – cheesemacfly Feb 24 '13 at 17:29
  • Well, you see.. the error is caused by the very code that I can't get working. So finding a solution for the rewrite will fix the error. – Nikita Feb 24 '13 at 17:33
  • But you said that the url `domain.com/example.cshtml` gives you a 404 error right? So when you hit `domain.com/folder/example.cshtml` it is redirected to `domain.com/example.cshtml` giving you a 404 error – cheesemacfly Feb 24 '13 at 17:37
  • Oh, I see. No sorry, the error is not what's important. The rewrite rule is, which I can't get to work. I have edited the question so you'll get what i really meant. – Nikita Feb 24 '13 at 17:43
  • Seems like you have asked 3 times the same question. Are you sure you know what you want? :) – cheesemacfly Feb 24 '13 at 17:58
  • I just want a rule so when you request: `domain.com/example` you actually get `domain.com/folder/example.cshtml`. It is much better explained in the other question of mine you commented on. – Nikita Feb 24 '13 at 18:05

2 Answers2

0

why aren't you using mod-rewrite?

RewriteCond %{THE_REQUEST} /folder/example.cshtml
RewriteRule ^$ /example.cshtml [R=301,L,NE]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^example.cshtml /folder/example.cshtml [L]

Sometimes you need to mess around with the slashes a bit

Dave
  • 433
  • 3
  • 9
  • The "not found" error is because you are re-directing to a directory structure that doesn't exist. re-writing isn't just how the address appears in your browser: it actually affects where the client looks for the file. A great tutorial about re-writing can be found at http://stackoverflow.com/questions/11709634/convert-original-url-to-friendly-url/11711948#11711948. – Dave Feb 24 '13 at 12:23
  • 1
    Can't use mod-rewrite with IIS servers. – Nikita Feb 24 '13 at 12:50
0

I guess it can't be done the way i want it. I'll have to move example.cshtml to the root directory.

Nikita
  • 609
  • 2
  • 7
  • 18
  • sorry, I forgot that you were on .net. I don't think the issue is a re-write issue, but instead has to do with how you configured the view associated with example.cshtml. – Dave Feb 24 '13 at 13:36