Redirection Subfolder Htaccess

北城以北 提交于 2019-12-13 07:16:45

问题


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.



来源:https://stackoverflow.com/questions/8273798/redirection-subfolder-htaccess

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!