Problem: I want to redirect from www.domain.com/index.php?mod=daily
to www.domain.com/daily_rent
While redirecting from www.domain.com/advert.php?id=11
to www.domain.com/advert/11
works fine like this:
RewriteCond %{THE_REQUEST} advert\.php\?id=([0-9]+)\ HTTP/
RewriteRule ^advert\.php$ http://www.domain.com/advert/%1? [R=301,L]
the same rule
RewriteCond %{THE_REQUEST} index\.php\?mod=daily\ HTTP/
RewriteRule ^index\.php$ http://www.domain.com/daily_rent? [R=301,L]
redirects to www.domain.com/daily_rent
and throws 404 error. What could be the reason?
UPD: Redirecting from www.domain.com/index.php?mod=daily
to www.domain.com/daily_rent
works fine, thanks anubhava
In that case another problem, on similar pages i have more than one query params, like this(example): www.domain.com/?mod=daily&room=1&area=bstn
so, i try use that rule
RewriteCond %{THE_REQUEST} \?mod=daily&room=([0-9]+)&area=([A-Z]+)\ HTTP/
RewriteRule ^$ http://www.domain.com/daily_rent/room/%1/area/%2? [R=301,L]
RewriteRule ^daily_rent/room/([0-9]+)/area/([A-Z]+)/?$ /?mod=daily&room=$1&area=$2 [QSA,L]
what is the solution for that situation? Thanks
Surely you want it the other way round - to redirect /daily_rent
to /index.php?mod=daily
? That would be a more common usage or mod_rewrite.
RewriteRule ^daily_rent$ /index.php?mod=daily [R=301,L]
You don't need the RewriteCond
Because you're missing internal rewrite rules. Try these rules:
RewriteCond %{THE_REQUEST} advert\.php\?id=([0-9]+)\s
RewriteRule ^advert\.php$ /advert/%1? [R=301,L]
RewriteCond %{THE_REQUEST} index\.php\?mod=(daily)\s
RewriteRule ^index\.php$ /%1_rent? [R=301,L]
RewriteRule ^(daily)_rent/?$ /index.php?mod=$1 [QSA,L]
RewriteRule ^advert/([^/]+)/?$ /advert.php?id=$1 [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.