Forum Moderators: coopster

Message Too Old, No Replies

.htaccess: open always index file!

no matter what url is entered

         

globay

7:28 pm on May 2, 2003 (gmt 0)

10+ Year Member



I need some help:

no matter what Url is entered, I want a file, lets say the index.php file in the root directory to be opened.

How can that be done?

(No redirects, the URl needs to stay the same, since I use URl rewriting, and the folders are parameters).

Thanks

--
globay

jdMorgan

7:59 pm on May 2, 2003 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



globay,

So, you want your web site to consist of only one page?

It would be helpful if you would provide more detail about what you are trying to do.

The simple answer is to use a server-internal rewrite, not an external (301 or 302) redirect.


RewriteRule .* /index.php [L]

But I don't think that is what you really want to do, since no-one would ever be able to get to any other page.

Jim

globay

12:32 am on May 3, 2003 (gmt 0)

10+ Year Member



I have a database driven site, that could look like this:

domain.com/index.php?cat=abc&subcat1=def&subcat2=ghi

Now I want to put the parameters like this

domain.com/abc/def/ghi

There is one file that processes the url and selects the content and the template from the database.

Now this file should allways be opened, no matter what URl is typed in.

One way to do it would look like this:

.htaccess:
<Files index>
ForceType application/x-httpd-php
</Files>

domain.com/index/abc/def/ghi

How can I do it, so that index/ does not appear in the URl

jdMorgan

12:44 am on May 3, 2003 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



globay,

RewriteRule ^([^/]*)/([^/]*)/(.*)$ /index.php?cat=$1&subcat1=$2&subcat2=$3 [L]

Will accept domain.com/abc/def/ghi and redirect to domain.com/index.php?cat=abc&subcat1=def&subcat2=ghi without changing the URL domain.com/abc/def/ghi in the browser address bar.

Reference: Introduction to mod_rewrite [webmasterworld.com]

Jim

globay

12:57 am on May 3, 2003 (gmt 0)

10+ Year Member



Yes, thanks jdMorgan,

that helped a lot! A still need to experiment a little with it, but I am confident, that it will work soon!

--
globay

DrDoc

4:31 pm on May 3, 2003 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



You can also do this.

.htaccess

ErrorDocument 404 /index.php

index.php

<?php
list($cat, $subcat1, $subcat2) = preg_split("#/#", $_SERVER['REQUEST_URI'], PREG_SPLIT_NO_EMPTY);
...
?>

globay

4:34 pm on May 3, 2003 (gmt 0)

10+ Year Member



Yes, that is what I was thinking, too:

[webmasterworld.com...]

But what about the 404 Header send out?

DrDoc

4:54 pm on May 3, 2003 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



I honestly don't have a good answer for that question...

For browsers it shouldn't matter, but it could cause issues with SE indexing. Maybe there's another .htaccess directive that could help?

globay

7:09 pm on May 3, 2003 (gmt 0)

10+ Year Member



I finally did, what jpMorgan suggested in the first place:

RewriteRule .* /index.php [L]

Somehow it didn't work for me at the beginning (maybe safemode?). After messing with 404, I tried it on a different server, and everything worked just perfectly!

Thanks to all,

globay

Skitz

3:13 pm on May 6, 2003 (gmt 0)



Globay,

I want to try something similar on a site I'm developing...

My inspiration: [alistapart.com...]

There's a little code snippet in there that might help.

Also, when I was experimenting with my hosting provider none of the rewrite directives worked at all until I added:
Options +FollowSymLinks to my .htaccess file.

I'm not entirely sure why but now they work as expected.

Skitz