Welcome to WebmasterWorld Guest from 54.163.35.238

Forum Moderators: Ocean10000 & incrediBILL & phranque

Message Too Old, No Replies

Problem with rewriting "index" on small CMS

     

Patrick Taylor

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

WebmasterWorld Senior Member 10+ Year Member



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

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

WebmasterWorld Senior Member 10+ Year Member



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

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

WebmasterWorld Senior Member jdmorgan is a WebmasterWorld Top Contributor of All Time 10+ Year Member



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

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

WebmasterWorld Senior Member 10+ Year Member



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

Patrick

 

Featured Threads

Hot Threads This Week

Hot Threads This Month