简体   繁体   中英

mod_rewrite to a directory

Im trying to create a rewrite rule to a different directory, but unfortunatly its not working.

My current rewrite sends everything back to the index.php file unless the first word in the query string is admin. The rewrite rule for 'admin' is to admin.php, but i actually want it to go to /var/www/html/website.com/admin/admin.php (instead of the file in the same directory).

This is current .htaccess file.

RewriteEngine On
RewriteRule ^(.*\/?).*(css|images|js/)+.*$ - [L]
RewriteRule ^\/?admin\/?(.*)$ admin.php?url=$1 [QSA,L]

RewriteRule ^(.*)$ index.php?url=$1 [QSA,L]

If i change the rewrite rule for admin to use a different directory..

RewriteRule ^\/?admin\/?(.*)$ /var/www/html/website.com/admin/admin.php?url=$1 [QSA,L]

It breaks the site. Any ideas?

Thanks.

It's actually quite simple, you're using the system path, while web path is needed.

Try the following line:

RewriteRule ^\/?admin\/?(.*)$ /subfolder/admin.php?url=$1 [QSA,L]

Try these rules:

RewriteRule ^admin($|/(.*)) admin/admin.php?url=$2 [QSA,L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule .* index.php?url=$0 [QSA,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