开发者

Can I use htaccess rewrite to remove part of a URL

I have a URL like开发者_StackOverflow中文版 the following:

www.domain.com/blog/about

The reason it is /blog first is because it is a WordPress site installed in a subfolder of my site called blog. Is it possible to remove the blog part of the URL with htaccess so that the URL would look like

www.domain.com/about 

but the page being served would be the /blog/about page?


You can do it with these rules however it will kill anything in your root directory!

RewriteCond $1 !^/blog
RewriteRule ^(.*)$ /blog/$1

You may want to add a check that the requested file/directory doesn't exist first e.g.

RewriteCond %{REQUEST_FILENAME} !-d 
RewriteCond %{REQUEST_FILENAME} !-f 

That way existing files would be served everything else gets directed to the blog


You can rewrite that using .htaccess, but a better solution would be to point the URL to the blog folder directy. Or you can move the content out of the blog folder.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜