Welcome to WebmasterWorld Guest from 54.163.168.15

Forum Moderators: Ocean10000 & incrediBILL & phranque

Apache Help Needed

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

5+ Year Member



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.
2:22 pm on May 5, 2010 (gmt 0)

WebmasterWorld Senior Member g1smd is a WebmasterWorld Top Contributor of All Time 10+ Year Member Top Contributors Of The Month



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.
4:23 pm on May 5, 2010 (gmt 0)

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



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
 

Featured Threads

My Threads

Hot Threads This Week

Hot Threads This Month