Redirection Subfolder Htaccess

2019-08-26 21:39发布

问题:

I want a redirect using htaccess I have a post name wordpressurl/curious and also a folder named curious What I want is if a user tries to access

  1. wordpressurl/curious
  2. wordpressurl/curious/
  3. wordpressurl/curious/subfolder

    note trailing slash in 1 and 2 and 3 is subdirectory. All of them should give 404 error wordpress page using htaccess only

Edited

# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /Wordpress_Work/realestate/
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d

RewriteRule . /Wordpress_Work/realestate/index.php [L]
</IfModule>

# END WordPress

回答1:

You can access the wordpress post that is the same as a curious directory by making the changes indicated below. Change curious to whatever your actual directory/post is.

<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /Wordpress_Work/realestate/
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f

#add an OR
RewriteCond %{REQUEST_FILENAME} !-d [OR]
#OR if the URI is curious or curious/ or curious/subfolder
RewriteCond %{REQUEST_URI} ^/Wordpress_Work/realestate/curious(/.*)?$ 

RewriteRule . /Wordpress_Work/realestate/index.php [L]
</IfModule>


回答2:

If you are putting RewriteCond %{REQUEST_FILENAME} !-d you can't have same name for the page and physical directory . that's the point of using it.

Try skipping the rewritecond , though I've never tried it before . for me , I'd change the page name or add a suffix.