简体   繁体   中英

Removing .php from url's in the htaccess, not i can't install wordpress on a sub folder

My site has been using the below code to remove the .php from the end of the URLs

RewriteCond %{REQUEST_FILENAME} !-f

RewriteRule ^([^/]+)/$ $1.php

RewriteRule ^([^/]+)/([^/]+)/$ /$1/$2.php

I've now installed wordpress in /clients/ on the folder but it's not working as it's rewriting wordpress as well which i don't want it to do but i'm not sure how to fix the above code to stop it happening in the sup folder.

full htaccess

RewriteEngine On

RewriteCond %{HTTP_HOST} !^www\.

RewriteRule ^(.*)$ http://www.%{HTTP_HOST}/$1 [R=301,L]


RewriteCond %{REQUEST_FILENAME} !-f

RewriteRule ^([^/]+)/$ $1.php

RewriteRule ^([^/]+)/([^/]+)/$ /$1/$2.php


RewriteCond %{REQUEST_FILENAME} !-f

RewriteCond %{REQUEST_FILENAME} !-d

RewriteCond %{REQUEST_URI} !(\.[a-zA-Z0-9]{1,5}|/)$

RewriteRule (.*)$ /$1/ [R=301,L]

# compress text, html, javascript, css, xml:

AddOutputFilterByType DEFLATE text/plain

AddOutputFilterByType DEFLATE text/html

AddOutputFilterByType DEFLATE text/xml

AddOutputFilterByType DEFLATE text/css

AddOutputFilterByType DEFLATE application/xml

AddOutputFilterByType DEFLATE application/xhtml+xml

AddOutputFilterByType DEFLATE application/rss+xml

AddOutputFilterByType DEFLATE application/javascript

AddOutputFilterByType DEFLATE application/x-javascript


# Or, compress certain file types by extension:

<FilesMatch "\.(php|html|css|js)$"> 

SetOutputFilter DEFLATE

</FilesMatch>

First of all your rewrite code doesn't look right. Here is the fixed code that will skip rewrite for /clients/ URI.

## hide .php extension
# To externally redirect /dir/foo.php to /dir/foo
RewriteCond %{THE_REQUEST} ^[A-Z]{3,}\s([^.]+)\.php [NC]
RewriteRule ^(?!clients/).*$ %1 [R,L,NC]

## To internally redirect /dir/foo to /dir/foo.php
RewriteCond %{REQUEST_FILENAME}.php -f [NC]
RewriteRule ^(?!clients/).*$ %{REQUEST_URI}.php [L,NC]

In the /clients/ folder add an .htaccess file with the following:-

RewriteEngine off

in it. This turns off mod_rewrite for that folder and it's children.

Voila

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM