简体   繁体   中英

.htaccess multiple RewriteRule's doesn't work

The multiple RewriteRule's doesn't work into my .htaccess file.

To get direct into the point, i have this lines of code into my .htaccess file

RewriteEngine On

RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)$ ./index.php?lang=$1 [L]

RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)/$ ./profile.php?page=$1 [L]

The problem is when i add a parameter into my domain, let's suppose www.eaxmple.com/something, i land always to home page. What i want to do is when i set a parameter with slash at the end to go to profile.php and without slash to move into index.php. Even if i tried to put a parameter i always move to index page.

Can someone help me?

.* will match everything including trailing / .

Try rules in this order:

RewriteEngine On

RewriteCond %{REQUEST_FILENAME} -f [OR]
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^ - [L][

RewriteRule ^(.+)/$ profile.php?page=$1 [L,QSA]

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

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