简体   繁体   中英

.htaccess Rewrite Parent Folder to Subfolder

I am looking to rewrite the url so if someone lands on a parent folder, they will be redirected to its subfolder. http://www.domain.com/portfolio should take me to http://www.domain.com/portfolio/example

RewriteEngine is on, and there are other RewriteRules in the file, which are working. I have tried the following rewrites, but none perform the redirect:

 RewriteRule ^/portfolio/(.*)$ /portfolio/example/$1 [R=301,L,QSA]

and

 RewriteCond %{HTTP_HOST} ^(www.)?domain.com/portfolio$
 RewriteRule ^(/)?$ portfolio/example[L,QSA]

and

 RewriteRule ^portfolio/(.*) http://www.domain.com/portfolio/example/$1 [R=301,L,QSA]

and

 RewriteRule ^portfolio$ http://www.domain.com/portfolio/example[R=301,L,QSA]
 RewriteRule ^portfolio/(.*) http://www.domain.com/portfolio/example$1 [R=301,L,QSA]

What is the proper syntax for rewriting a url so that if a visitor lands on the parent portfolio folder, they go to the portfolio/example subfolder?

Put this code in your DOCUMENT_ROOT/.htaccess file:

RewriteEngine On

RewriteRule ^portfolio(/(?!example).*|)$ /portfolio/example$1 [R=301,L,NC]

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