简体   繁体   中英

Internal rewrite to remove directory from url with htaccess

I've searched and tried many tutorials and problem solutions but couldn't achieve what I want.

If user open domain.com/xxx.php he see the content of domain.com/hosting/xxx.php

This RewriteRule ^xxx.php$ /hosting/xxx.php

Works perfectly what i want to do, but there are over 150 pages in hosting directory and writing rules for each page does not seem right? any possible way to do it dynamically?

I tried this solution it works but it try to find those pages which are currently at root domain.com/xxx.php inside domain.com/hosting/

I search slimier questions have been asked many times before but non of the answer worked for me.

You need to also take care of reuests to the shortened, rewritten URL:

RewriteEngine on
RewriteRule ^/?hosting/(.*)$ /$1 [END,NC,R=302]
RewriteRule ^/?(.*)$ /hosting/$1 [END]

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