My htaccess
looks like the following:
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_URI} !^some-string/$ [NC]
RewriteRule ^some-string(.*)$ http://www.domain.com$1 [R=301,L]
So all requests from www.domain.com/some-string/xxx should be redirected to www.domain.com/xxx (from subfolder to main domain). Now I had the problem that an article contained exactly the some-string
part in his name eg www.domain.com/some-string-is-here. The result is that the article is not found.
How do I have to adapt the redirect?
Making the RewriteRule
a bit more specific should help; in that case the RewriteCond
is not necessary. As only requests starting with some-string/
(including the /
) should be rewritten, appending that /
to the rule does the trick for me:
RewriteEngine On
RewriteBase /
RewriteRule ^some-string/(.*)$ http://www.domain.com/$1 [R=301,L]
If you also want to rewrite www.domain.com/some-string
(and only this and not www.domain.com/some-string-more
), you can try instead:
RewriteRule ^some-string(/.*)?$ http://www.domain.com$1 [R=301,L]
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.