-1

What i want:

  • Force www [works]
  • Restrict access to .inc.php [works]
  • Force redirection of abc.php to /abc/
  • Removal of extension from url
  • Add a trailing slash if needed

old .htaccess :

    Options +FollowSymLinks


    <IfModule mod_rewrite.c>

    RewriteEngine On
    RewriteBase /

    ### Force www
    RewriteCond %{HTTP_HOST} ^example\.net$
    RewriteRule ^(.*)$ http://www\.example\.net/$1 [L,R=301]


    ### Restrict access
    RewriteCond %{REQUEST_URI} ^/(.*)\.inc\.php$ [NC]
    RewriteRule .* - [F,L]


    #### Remove extension:
    RewriteRule ^(.*)/$ /$1.php [L,R=301]



    ######### Trailing slash:
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_URI} !(.*)/$
    RewriteRule ^(.*)$ http://www.example.net/$1/ [R=301,L]
    </IfModule>

New .htaccess:

     Options +FollowSymLinks


     <IfModule mod_rewrite.c>

    RewriteEngine On
    RewriteBase /

    ### Force www
    RewriteCond %{HTTP_HOST} ^example\.net$
    RewriteRule ^(.*)$ http://www\.example\.net/$1 [L,R=301]


    ### Restrict access
    RewriteCond %{REQUEST_URI} ^/(.*)\.inc\.php$ [NC]
    RewriteRule .* - [F,L]


    #### Remove extension:
    RewriteCond %{REQUEST_FILENAME} \.php$
    RewriteCond %{REQUEST_FILENAME} -f
    RewriteRule (.*)\.php$ /$1/ [L,R=301]

    #### Map pseudo-directory to PHP file
    RewriteCond %{REQUEST_FILENAME}\.php -f
    RewriteRule (.*) /$1.php [L]

    ######### Trailing slash:
    RewriteCond %{REQUEST_FILENAME} -d
    RewriteCond %{REQUEST_FILENAME} !/$
    RewriteRule (.*) $1/ [L,R=301]

    </IfModule>

errorlog:

     Request exceeded the limit of 10 internal redirects due to probable configuration error. Use 'LimitInternalRecursion' to increase the limit if necessary. Use 'LogLevel debug' to get a backtrace., referer: http://www.example.net/

Rewrite.log: http://pastebin.com/x5PKeJHB

Shoaibi
  • 789
  • 1
  • 9
  • 28

2 Answers2

0

This seems to be your initial problem:

#### Map pseudo-directory to PHP file
RewriteCond %{REQUEST_FILENAME}\.php -f
RewriteRule (.*) /$1.php [L]

You're trapping a '/' character.

119.154.34.231 - - [03/Oct/2010:16:17:06 +0000] [www.example.net/sid#7f3fa2d89670][rid#7f3fa3466b58/initial] (4) [perdir /var/www/example.net/public_html/] RewriteCond: input='/var/www/example.net/public_html/how-works.php' pattern='-f' => matched

119.154.34.231 - - [03/Oct/2010:16:17:06 +0000] [www.example.net/sid#7f3fa2d89670][rid#7f3fa3466b58/initial] (2) [perdir /var/www/example.net/public_html/] rewrite 'how-works/' -> '/how-works/.php'

Try:

RewriteRule ^/(.*)/(.?) /$1.php [L]

...I might have that a bit wrong, but that seems like where you're first going wrong.

0

You are catching the trailing slash you added in the "remove extension" block in the next block, which breaks the call to the local file, and will keep tacking on .php's since the "trailing slash" block will never match so it wraps back around to the "Map psudo-dir" block.

Add '(/?)' backreference, do you don't accidentally have "/" in your $1 #### Map pseudo-directory to PHP file RewriteCond %{REQUEST_FILENAME}.php -f RewriteRule /(.*)(/?) /$1.php [L]

and, the "-d" should be a "-f" from what i can tell:

### Trailing slash:
RewriteCond %{REQUEST_FILENAME} -f
RewriteCond %{REQUEST_FILENAME} !/$
RewriteRule (.*) $1/ [L,R=301]

Though This seems somewhat convoluted. You should just have your site link to the "/abc/" dir instead of directly to the php files, and redirect those.

Ali Chehab
  • 451
  • 2
  • 5