I would like to do this globally via htaccess rewrite so any www.domain.com/wildcard/ would == www.domain.com/new_segment/wildcard/ but I can't seem to figure this out.
So far, I have the following:
Options +FollowSymLinks -MultiViews
RewriteCond %{HTTP_HOST} ^domain\.com$ [OR]
RewriteCond %{HTTP_HOST} ^www\.domain\.com$
RewriteRule ^(.*)$ "http\:\/\/www\.domain\.com\/new_segment\/$1" [R=301,L]
For some reason, on the initial page load I get www.domain.com/new_segment/new_segment/ but if I go to www.domain.com/old_segment I would expect www.domain.com/new_segment/old_segment/ but I get www.domain.com/old_segment/ instead.
Any help would be greatly appreciated.
Why would you want that? Anyways, you can do it easier by putting desired files into a directory and a redirection from a file on the /old_segment to /new_segment.
This can be done with:
RewriteEngine On
RewriteCond %{REQUEST_URI} !^/new_segment
RewriteRule ^(.*)$ /new_segment/$1 [R=301,L]
It will check to see if the new_segment
isn't in the url, if it is then nothing will be redirected. If it isn't then new_segment
will be added.
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.