homepage Welcome to WebmasterWorld Guest from 54.197.94.241
register, free tools, login, search, pro membership, help, library, announcements, recent posts, open posts,
Become a Pro Member
Home / Forums Index / Code, Content, and Presentation / Apache Web Server
Forum Library, Charter, Moderators: Ocean10000 & incrediBILL & phranque

Apache Web Server Forum

    
Problem with rewriting "index" on small CMS
Patrick Taylor




msg:3577276
 5:30 pm on Feb 17, 2008 (gmt 0)

I have a small php CMS I've written myself. There's no database - it writes .php and .txt files into a subfolder called /cms. The .htaccess file rewrites /page to /cms/page.php and this works fine (see below).

The problem arises with "index", the home page. The CMS writes the home page content to /cms/index.php and /cms/index.txt and the .htaccess file second part rewrites a request for www.example.com/ to www.example.com/index where the content actually is (there is no index file in the root folder). This all seems to work fine too.

But I don't want www.example.com/index to be accessible in a browser, for obvious reasons. I've tried all manner of things but no success.

#
# Rewrite "string" everything to cms folder
RewriteRule ^([a-z0-9-]+)$ /cms/$1.php [L]
#
# Now Rewrite "/" to "/index" where the resource actually is
RewriteCond %{REQUEST_URI} ^/$
RewriteRule .? http://www.example.com/index [L]
#
# Now Rewrite "index" to "/" - NEXT LINE DOESN'T WORK
RewriteRule ^index$ http://www.example.com/ [L]
#

The second two RewriteRules seem to be working against each other. Any assistance would be appreciated.

Patrick

 

Patrick Taylor




msg:3577361
 9:02 pm on Feb 17, 2008 (gmt 0)

I worked it out.

#
# Rewrite "string" everything to /cms folder
RewriteCond %{REQUEST_URI} !^/index$
RewriteRule ^([a-z0-9-]+)$ /cms/$1.php [L]
#
# Rewrite "/" to "/cms/index.php"
RewriteCond %{REQUEST_URI} ^/$
RewriteRule .? /cms/index.php [L]
#

Patrick

[edited by: Patrick_Taylor at 9:04 pm (utc) on Feb. 17, 2008]

jdMorgan




msg:3577402
 10:32 pm on Feb 17, 2008 (gmt 0)

You don't really need a RewriteCond for rule #2:
[/code]
# Rewrite "/" to "/cms/index.php"
RewriteRule ^$ /cms/index.php [L]
[/code]
Jim

Patrick Taylor




msg:3577412
 10:42 pm on Feb 17, 2008 (gmt 0)

Many thanks. I didn't realize one could use ^$ to match "nothing".

Patrick

Global Options:
 top home search open messages active posts  
 

Home / Forums Index / Code, Content, and Presentation / Apache Web Server
rss feed

All trademarks and copyrights held by respective owners. Member comments are owned by the poster.
Home ¦ Free Tools ¦ Terms of Service ¦ Privacy Policy ¦ Report Problem ¦ About ¦ Library ¦ Newsletter
WebmasterWorld is a Developer Shed Community owned by Jim Boykin.
© Webmaster World 1996-2014 all rights reserved