简体   繁体   中英

.htaccess rule appending index.php instead of URI

My .htaccess looks like this..

Options -Indexes

<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)$ index.php [QSA,L]

RewriteCond %{HTTP_HOST} ^sub\.domain\.com$ [NC]
RewriteRule ^(.*)$ https://www.domain.com/members/invite/$1 [R,L]

</IfModule>

I want to be able to redirect an URL that looks like this..

https://sub.domain.com/ZTHF76

to...

https://www.domain.com/members/invite/ZTHF76

But instead I am getting

https://www.domain.com/members/invite/index.php

I need to keep the first rule to remove index.php from the URI of the rest of the application.

Any help with this greatly appreciated.

You should reorder your rules and keep redirect rule before rewrite one:

Options -Indexes
RewriteEngine On

RewriteCond %{HTTP_HOST} ^sub\.domain\.com$ [NC]
RewriteRule ^(.*)$ https://www.domain.com/members/invite/$1 [L,R=302]

RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ index.php [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