Forum Moderators: phranque

Message Too Old, No Replies

rewrite gives 404 when directory doesn't exist

         

bakiido

7:16 pm on Dec 16, 2008 (gmt 0)

10+ Year Member



I have the following problem.

Using the .htaccess file

RewriteEngine On
Options +FollowSymLinks
rewriteRule ^tasks(/?)$ index.php?op=tasks$
rewriteRule ^projects(/?)$ index.php?op=projects$

If the folders tasks/ and projects/ exist, even empty, it works fine, but if they don't exist I get 404 not found.

I not that it should be possible to do this without creating folder, what is the trick?

g1smd

8:24 pm on Dec 16, 2008 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



The final $ on the very end of both lines should be removed.

The /? notation is very dangerous, creating duplicate content.

jdMorgan

9:13 pm on Dec 16, 2008 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



What version of Apache are you using?

Jim

g1smd

11:20 pm on Dec 16, 2008 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



Add [L] to the very end of both rules when you remove the final $ sign at the very end.

bakiido

10:23 am on Dec 17, 2008 (gmt 0)

10+ Year Member



version: Apache/2.2.9 (Debian) PHP/5.2.6-5 with Suhosin-Patch mod_ssl/2.2.9 OpenSSL/0.9.8g

The following rules, also don't work

RewriteRule ^tasks index.php?op=$1 [L]
RewriteRule ^projects index.php?op=$1 [L]

I have other .htaccess file on the main folder. Do you think that maybe I should put all the rules in the root(main) folder?

g1smd

10:42 am on Dec 17, 2008 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



Since no back reference is created in either rule, the $1 usage will always yield a blank value there.

You changed too many things at once, changing things that didn't need changing.

The original instruction was to remove the "dollar sign at the very end".

bakiido

10:49 am on Dec 17, 2008 (gmt 0)

10+ Year Member



Yes, I forgot to remove the '$1' I tried this now and also don't work.

RewriteRule ^tasks index.php?op=tasks
RewriteRule ^projects index.php?op=projects

but it works, if the folders tasks/ and projects/ exist. That it the strange thing. Isn't it?

bakiido

10:55 am on Dec 17, 2008 (gmt 0)

10+ Year Member



In the same file I have other rule:

RewriteRule ^$ index.php?op=overview

and this one works fine!

bakiido

12:26 pm on Dec 17, 2008 (gmt 0)

10+ Year Member



I tried putting different name like this

RewriteEngine On
Options +FollowSymLinks
rewriteRule ^tasks1/?$ index.php?op=tasks$
rewriteRule ^projects1/?$ index.php?op=projects$

and it works.

what it is the difference between tasks1 and tasks? I remove folders with names tasks/ and projects/ from the folder. There is something blocking this two names?

g1smd

12:55 pm on Dec 17, 2008 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



For the last time.

Remove the final $ sign from the very end of both of your rules.

Add [L] to the very end of both of your rules.

The /? notation is very dangerous because it creates Duplicate Content. Choose one or the other as being the valid URL for that content.

bakiido

2:12 pm on Dec 17, 2008 (gmt 0)

10+ Year Member



I did that, but that isn't the problem.

Now, this works

RewriteRule ^overview/tasks1/$ /~pbtz/temp/sqig/overview/index.php?op=tasks

this doesn't, gives 404

RewriteRule ^overview/projects/$ /~pbtz/temp/sqig/overview/index.php?op=projects

It seems to be some problem with the name /projects
since if I change it for something else, it works.

What can be blocking the use of this name?

bakiido

2:14 pm on Dec 17, 2008 (gmt 0)

10+ Year Member



Moreover, [L] doesn't do any difference in both cases!

Caterham

5:21 pm on Dec 17, 2008 (gmt 0)

10+ Year Member



I remove folders with names tasks/ and projects/ from the folder. There is something blocking this two names?
If files or folders exist with that name, may be content negation. But anyway, that should not result in a 404 if negation takes place. If you don't use content negation and your server config enables MultiViews, disable the setting again:

Options -MultiViews

bakiido

5:28 pm on Dec 17, 2008 (gmt 0)

10+ Year Member



That is the solution! thank you! :)

jdMorgan

6:23 pm on Dec 17, 2008 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



And again, add [L] to all of your RewriteRules, unless you have a very good reason not to use it.

Jim

bakiido

6:45 pm on Dec 17, 2008 (gmt 0)

10+ Year Member



OK!

Why doesn't work relative path:

RewriteRule ^tasks/$ index.php?op=tasks

Just

RewriteRule ^tasks1/$ /~pbtz/temp/sqig/overview/index.php?op=tasks

jdMorgan

7:11 pm on Dec 17, 2008 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Because you are apparently using Apache mod_userdir, and the DocumentRoot configured in your server configuration file must point to a level above the users such as "~pbtz" in order for these ~user directories to function.

Jim

Caterham

8:18 pm on Dec 17, 2008 (gmt 0)

10+ Year Member



Why doesn't work relative path:

Use the RewriteBase directive to specify the URL-path under which you can reach the directory from "outside".
Syntax:
RewriteBase /~pbtz/temp/sqig/overview/