I've spent a lot of time looking around and have unfortunately not been able to come up with anything that works.
I have an address in the following format:
subdomain.domain.com/ugly/path
that I want to prettify to:
subdomain.domain.com/newpath
How do I do this using .htaccess?
I'm not sure if this changes anything but the subdomain is simply an A record pointing to an IP address. There is no folder on the server.
You can use this code in your DOCUMENT_ROOT/.htaccess
file:
RewriteEngine On
RewriteCond %{HTTP_HOST} =subdomain.domain.com
RewriteCond %{THE_REQUEST} \s/+ugly/path/(\S*)\s [NC]
RewriteRule ^ /%1 [L,R=302]
RewriteRule ^newpath(/.*)?$ ugly/path$1 [L,NC]
if the /ugly/ really is not necessary than you can simply move the content to your subdomain folder.
what you have currently is ...............
subdomain.domain.com/ugly/path1 (rootfolder/subdomain/ugly/path1)
subdomain.domain.com/ugly/path2 (rootfolder/subdomain/ugly/path1)
what you need to change is ............
rootfolder/subdomain/ugly/path1 ---> rootfolder/subdomain/path1
rootfolder/subdomain/ugly/path1 ---> rootfolder/subdomain/path1
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.