简体   繁体   中英

.htaccess file to redirect all pages except the wp-admin dashboard

I have redirected the all pages of my wp site from .php extension to / For example, I am redirect pages such as example.com/about-us.php to example.com/about-us/ but, It is also redirecting my example.com/wp-admin dashboard page which I don't want to redirect.How can I prevent it from redirecting? Here is my .htaccess code.

Options +FollowSymLinks -MultiViews
RewriteEngine On
RewriteBase /

# redirect to .php-less link if requested directly
RewriteCond %{THE_REQUEST} ^[A-Z]+\s.+\.php\sHTTP/.+
RewriteRule ^(.+)\.php $1 [R=301,L]

Are you sure you want the 301 redirect ( R=301 )? Surely you want the URL to look like it doesn't have .php but under the hood you still want to access the respective php script?

Anyway, how about this - two conditions:

  1. must not have wp- in the request URI
  2. must end in .php

Like this:

RewriteCond %{REQUEST_URI} !wp-
RewriteCond %{REQUEST_URI} \.php$
RewriteRule ^(.+)\.php $1 [R=301,L,QSA]

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