简体   繁体   中英

htacess redirect an external directory

I'm building a Wordpress site and I want to change the url of an external directory with .htaccess because I don't want my repository's name to be in the url.

The url of the external directory is

"http://localhost:10012/wordpress_externaldirectory/lp/sample"

I want to change this url to

"http://localhost:10012/lp/sample"

So, I wrote this in my htaccess file.

RewriteEngine on
RewriteRule ^wordpress-externaldirectory/(.*)$ //$1 [R=301,L]

I expected that if you hit /lp/sample, you can access /wordpress_externaldirectory/lp/sample", but it did not work.

does anyone have an idea why it is not working? thanks in advance

You only went half of the way. You only redirected requests using the "old" URL. You forgot to internally rewrite requests to the "new" URL, to map those the the actual internal ressource ...

Have a try along these lines:

RewriteEngine on
RewriteRule ^/?wordpress-externaldirectory/(.*)$ /$1 [R=301,L]
RewriteCond %{REQUEST_URI} !^/wordpress-externaldirectory/
RewriteRule ^ /wordpress-externaldirectory%{REQUEST_URI} [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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM