Apache Development
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me
Go Back   Dev Shed ForumsSystem AdministrationApache Development

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
  #1  
Old October 22nd, 2000, 04:09 AM
Krucifyx Krucifyx is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jun 2000
Posts: 41 Krucifyx User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 9
First off, I'm trying this using apache on Win2k, so I'm not even sure if it'll work.

The server one of my sites is hosted on doesn't allow me to access a file without an extension, so in the .htaccess file, how can I force it so that all attempts at accessing /dir/file redirect to /dir/file.php?

Reply With Quote
  #2  
Old October 22nd, 2000, 07:26 AM
freebsd
Guest
Dev Shed Newbie (0 - 499 posts)
 
Posts: n/a  
Time spent in forums:
Reputation Power:
>>I'm trying this using apache on Win2k

I don't know if you can use mod_rewrite on Win2k either. Here is the code anyway..

#############################################

#http://www.yourdomain.com/.htacces
RewriteEngine on
RewriteCond %{REQUEST_URI} ^/([/A-Za-z0-9_]*)?([A-Za-z0-9_]+)$
RewriteRule ^(.*) http://www.yourdomain.com/$1.php [R]

#############################################

Note, all request (file or dir) WITHOUT a trailing slash or WITHOUT a dot will be handled by this Rewrite rules and EXTERNAL redirect and add .php to the end.

Take a close look at the following examples and see what will my rewrite rules do for you:

1) http://www.yourdomain.com/foo -> http://www.yourdomain.com/foo.php

2) http://www.yourdomain.com/foo/ -> http://www.yourdomain.com/foo/ (no change as long as foo directory exists)

3) http://www.yourdomain.com/foo/bar -> http://www.yourdomain.com/foo/bar.php

4) http://www.yourdomain.com/foo/bar/ -> http://www.yourdomain.com/foo/bar/ (no change as long as bar directory exists)

5) http://www.yourdomain.com/foo/bar/123/456 -> http://www.yourdomain.com/foo/bar/123/456.php

6) http://www.yourdomain.com/foo/bar/123/456/ -> http://www.yourdomain.com/foo/bar/123/456/ (no change as long as 456 exists)

7) http://www.yourdomain.com/foo/bar.html -> http://www.yourdomain.com/foo/bar.html (no change, note the file bar.html, as it has a dot, so it displays as is)

If you can tell me what is the EXACT NAME of that "dir" and its URL path relative to your http://www.yourdomain.com, it would run alot faster. Be sure to provide more example, not just /dir/file. I also need to know whether it's just /dir/file or /dir/subdir/file.

Finally, if apache on win32 can't use mod_rewrite, simply ignore this thread.

[This message has been edited by freebsd (edited October 22, 2000).]

Reply With Quote
  #3  
Old October 22nd, 2000, 09:16 PM
Krucifyx Krucifyx is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jun 2000
Posts: 41 Krucifyx User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 9
All the files will be located in the root directory. I tried what you sent me, but I guess I was wrong in what I wanted. The htaccess literally forwards the user to the file (people accessing /test are transported to /test.php), but I want it so that it is always just /test, so that I can use the script like /test/key1/value1/key2/value2, and so on. Thanks. I knew I should have paid more attention to regex in class...

Reply With Quote
  #4  
Old October 22nd, 2000, 11:06 PM
freebsd
Guest
Dev Shed Newbie (0 - 499 posts)
 
Posts: n/a  
Time spent in forums:
Reputation Power:
>>but I want it so that it is always just
/test

How many different name of /test are there? Would it be /another_test ? Since you haven't given enough examples, I still don't know exactly what you really want.

>>people accessing /test are transported to /test.php

I am not sure what you mean by "transported"? Do you want the browser location stays the same as is (i.e. /test) and INTERNAL redirect to /test.php? If so, change the [R] to [L].

RewriteRule ^(.*) http://www.yourdomain.com/$1.php [L]

Test this first, if it doesn't work, just take a look at my another post in this forum -> http://www.devshed.com/Talk/Forums/Forum15/HTML/000274.html


Reply With Quote
  #5  
Old October 23rd, 2000, 05:46 AM
Krucifyx Krucifyx is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jun 2000
Posts: 41 Krucifyx User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 9
My overall goal is to make it so that the file test.php is extensionless to the user. I then plan to replace ? with / as the query designation to make the site search engine friendly.

So:
http://www.mydomain.com/file.php?this=that

Would become:
http://www.mydomain.com/file/this/that

However, Apache keeps trying to access a directory for /file/this/that, instead of the file file.php

I can do /file.php/this/that just fine, but without the extension, the server keeps trying to access a directory.

Thanks for the support, I REALLY appreciate it.

Reply With Quote
  #6  
Old October 23rd, 2000, 01:36 PM
freebsd
Guest
Dev Shed Newbie (0 - 499 posts)
 
Posts: n/a  
Time spent in forums:
Reputation Power:
>>My overall goal is to make it so that the file test.php is extensionless to the user

You said your host doesn't allow you to access a file without extension, I think you interpret this incorrectly. Were you trying to say that a file without extension can be treated as a PHP script? If so, try this:

RewriteEngine on
RewriteCond %{REQUEST_URI} ^/([/A-Za-z0-9_]*)?([A-Za-z0-9_]+)$
RewriteRule ^(.+) http://www.yourdomain.com/$1 [T=application/x-httpd-php,L]

i.e. http://www.yourdomain.com/file/this/that

Note, this just force your extensionless file , specifically "that", as a PHP file, not "file".

>>to make the site search engine friendly

Here say it all -> http://www.devshed.com/Talk/Forums/Forum15/HTML/000274.html Since you are asking for the same thing, I am not going to repost the exact content.

Reply With Quote
Reply

Viewing: Dev Shed ForumsSystem AdministrationApache Development > Damn mod rewrite


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 5 hosted by Hostway
Stay green...Green IT