homepage Welcome to WebmasterWorld Guest from 54.226.191.80
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

    
Apache Help Needed
mkingsle




msg:4127360
 1:55 pm on May 5, 2010 (gmt 0)

I thought I would attach another issue that I am currently having. I have the following .htaccess:

DefaultType application/x-httpd-php

AddHandler x-httpd-php .php4
Options +FollowSymLinks
RewriteEngine on
RewriteCond %{THE_REQUEST} ^[A-Z]+\ /[^.#?\ ]+\.php([#?][^\ ]*)?\ HTTP/
RewriteRule ^([^.]+)\.php$ h**p://www.mysite.com/$1 [R=301,L]
RewriteCond %{HTTP_HOST} ^mysite\.com
RewriteRule ^(.*)$ h**p://www.mysite.com/$1 [R=permanent,L]

With jdMorgans useful advice, I have had success with the above. One issue that I am currently having is that I would like to be able to have all my index pages from my sub directories drop the /index part. I have seen other solutions that would work, but not combined with my code above, which drops the .php from my files. Any help is appreciated.

 

g1smd




msg:4127379
 2:22 pm on May 5, 2010 (gmt 0)

The standard two-line index redirect code (posted hundreds of times before), listed before all of your existing redirects will fix the problem.

Do add #comments to each of your rules explaining what each one does. The comment goes on a new line before each RewriteCond. Add a blank line after each RewriteRule too.

jdMorgan




msg:4127492
 4:23 pm on May 5, 2010 (gmt 0)

You're apparently asking about one thing, but posting a code example that does something different...

This may be what you are trying to do (Note how nice it is to have good comments) :

# Redirect direct client requests for /index.php in any directory to "/" in that directory
RewriteCond %{THE_REQUEST} ^[A-Z]+\ /([^/?#\ ]+/)*index\.php([?#][^\ ]*)?\ HTTP/
RewriteRule ^(([^/]+/)*)index\.php$ http://www.example.com/$1 [R=301,L]
#
# Redirect direct client requests to remove .php extensions
RewriteCond %{THE_REQUEST} ^[A-Z]+\ /[^?#\ ]+\.php([?#][^\ ]*)?\ HTTP/
RewriteRule ^(.+)\.php$ http://www.example.com/$1 [R=301,L]
#
# Redirect all non-blank non-canonical hostname requests to canonical hostname
RewriteCond %{HTTP_HOST} !^(www\.example\.com)?$
RewriteRule ^(.*)$ http://www.example.com/$1 [R=301,L]

Jim

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