简体   繁体   中英

htaccess rewrite rules in separate directories

I have a directory called "private". You can access the index.php file by using the url

http://www.example.com/private/

The index.php looks for the "page" parameter to require_once() the requested page.

http://www.example.com/private/?page=archive .

I wanted to make a rewrite rule to return the same query when user types:

http://www.example.com/private/archive .

I tried this rule but it doesn't seem to work.

RewriteEngine On
RewriteRule ^private/([a-z]+)/?$ private/?page=$1 [L]

The .htaccess doesn't want to work if I put it inside the "private" folder or the site's root. Isn't it suppose to be in the "private" folder instead of the root? My rewrite module is on.

Forgot to add "RewriteBase"

RewriteEngine On
RewriteBase /private/

RewriteRule ^([a-z]+)/?$ ?page=$1 [L]

There's no need to write "private/" in the rewrite rule since the rewrite base has been set to it. The .htaccess file should be inside the private folder of course.

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