SitePoint Sponsor |
|
User Tag List
Results 1 to 11 of 11
-
Mar 23, 2005, 10:47 #1
- Join Date
- Mar 2005
- Posts
- 42
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
RewriteRule doesn't behave the same way on live server
I have a .htaccess file with the following rules
Code:RewriteEngine on RewriteRule ^$/index.php [L] RewriteRule ^([a-zA-Z0-9\-\_/]*)/$ /$1/index.php [L] RewriteRule ^([a-zA-Z0-9\-\_/]*)\.(html|htm)$ /$1.php [L] RewriteRule ^([a-zA-Z0-9\-\_/]*)$ /$1.php [L]
After some head scratching, i found out that this url (http://www.liveserver.com/cp.php/landscape/) works.... how come? does it has something to do with the Apache config??
-
Mar 23, 2005, 13:57 #2
- Join Date
- Jan 2005
- Location
- Siegen, Germany
- Posts
- 51
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
no rule would match for /cp/landscape/
RewriteEngine on
RewriteRule ^$ /index.php [L]
RewriteRule ^([a-zA-Z0-9\-_/]+)/$ /$1/index.php [L]
# /cp/landscape/ or /cp/landscape.htm/.html --> /cp.php
RewriteRule ^([a-zA-Z0-9\-_/]+)/([a-zA-Z0-9\-_/]+/?|html?)$ /$1.php [L]
-
Mar 23, 2005, 16:20 #3
- Join Date
- Mar 2003
- Location
- England, UK
- Posts
- 2,906
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
Also this:
Code:RewriteRule ^([a-zA-Z0-9\-_/]+)/$ /$1/index.php [L]
Code:RewriteRule ^([a-zA-Z0-9\-_/]+)/?$ /$1/index.php [L]
-
Mar 23, 2005, 18:50 #4
- Join Date
- Feb 2002
- Location
- Auckland
- Posts
- 14,692
- Mentioned
- 20 Post(s)
- Tagged
- 3 Thread(s)
bian,
[QUOTE=bianster]Code:RewriteEngine on RewriteRule ^$/index.php [L] RewriteRule ^([a-zA-Z0-9\-\_/]*)/$ /$1/index.php [L] RewriteRule ^([a-zA-Z0-9\-\_/]*)\.(html|htm)$ /$1.php [L] RewriteRule ^([a-zA-Z0-9\-\_/]*)$ /$1.php [L]
I suspect that it's the leading slashes in the redirect (not the unnecessary escape - backslashes - in the atom's square brackets) nor the lack of space between the ^$ and /index.php in the first rule.
Try eliminating those leading slashes in the redirections and see if that doesn't resolve your problem (it's a major difference between Windows-based test servers and Linux production [online] servers).
Regards,
DKDavid K. Lynn - Data Koncepts is a long-time WebHostingBuzz (US/UK)
Client and (unpaid) WHB Ambassador
mod_rewrite Tutorial Article (setup, config, test & write
mod_rewrite regex w/sample code) and Code Generator
-
Mar 27, 2005, 02:58 #5
- Join Date
- Mar 2005
- Posts
- 42
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
thanks for the quick replies, haven't have a chance to try out the suggestions yet though
-
Apr 21, 2005, 02:47 #6
- Join Date
- Mar 2005
- Posts
- 42
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
[QUOTE=dklynn]bian,
Originally Posted by bianster
i've tried removing the leading slashes in the redirect but it didn't seem to fix the problem
-
Apr 21, 2005, 18:43 #7
- Join Date
- Feb 2002
- Location
- Auckland
- Posts
- 14,692
- Mentioned
- 20 Post(s)
- Tagged
- 3 Thread(s)
bianster,
Okay, let's start all over with the regex: What do you want to redirect and what should it be redirected to?
From my read of your code,
Code:RewriteEngine on RewriteRule ^$/index.php [L] #1 blank => index.php BUT you've GOT to separate the $ and /!!! RewriteRule ^([a-zA-Z0-9\-\_/]*)/$ /$1/index.php [L] #2 redirect "everything without dots" followed by a slash # to that as a subdirectory then it's index.php file RewriteRule ^([a-zA-Z0-9\-\_/]*)\.(html|htm)$ /$1.php [L] #3 redirect "everything without dots" as htm or html filenames # to PHP scripts with the same name RewriteRule ^([a-zA-Z0-9\-\_/]*)$ /$1.php [L] #4 redirect "everything without dots" to a php script # of the same name
That said, http://localhost/cp/landscape/ should be picked up by #2 on both servers. http://www.liveserver.com/cp.php/landscape/ should NOT (because of the dot in cp.php).
Regards,
DKDavid K. Lynn - Data Koncepts is a long-time WebHostingBuzz (US/UK)
Client and (unpaid) WHB Ambassador
mod_rewrite Tutorial Article (setup, config, test & write
mod_rewrite regex w/sample code) and Code Generator
-
Apr 21, 2005, 22:52 #8
- Join Date
- Mar 2005
- Posts
- 42
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
well, actually what I want to is to have either cp.php or public.php to handle all requests that start with cp or public, eg, http://www.liveserver.com/cp/landscape/ OR http://www.liveserver.com/public/landscape/.
-
Apr 22, 2005, 00:27 #9
- Join Date
- Feb 2002
- Location
- Auckland
- Posts
- 14,692
- Mentioned
- 20 Post(s)
- Tagged
- 3 Thread(s)
bianster,
Originally Posted by bianster
In other words, you want to redirect ^(cp|public)/(.*)$ to $1.php?something=$2 [L] if I read your reply correctly. Wanna confirm OR tell what your regex is supposed to be redirected to?
Regards,
DKDavid K. Lynn - Data Koncepts is a long-time WebHostingBuzz (US/UK)
Client and (unpaid) WHB Ambassador
mod_rewrite Tutorial Article (setup, config, test & write
mod_rewrite regex w/sample code) and Code Generator
-
Apr 22, 2005, 00:46 #10
- Join Date
- Mar 2005
- Posts
- 42
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
Yeah, that was exactly what I was trying to do, thanks a lot man!
-
Apr 22, 2005, 00:48 #11
- Join Date
- Feb 2002
- Location
- Auckland
- Posts
- 14,692
- Mentioned
- 20 Post(s)
- Tagged
- 3 Thread(s)
bianster,
Horray!
I must be good at guessing
Regards,
DKDavid K. Lynn - Data Koncepts is a long-time WebHostingBuzz (US/UK)
Client and (unpaid) WHB Ambassador
mod_rewrite Tutorial Article (setup, config, test & write
mod_rewrite regex w/sample code) and Code Generator
Bookmarks