Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Htaccess rewrite in subfolder with parameters

I'm trying to rewrite /streams/post.php?id=1 into /streams/thread/1 .

I did find some codes for .htaccess with parameters but it didn't work in the subfolder.

Also, should I put another .htaccess in the subfolder or use the one on the main directory? ( /.htaccess or /streams/.htaccess)

Also, in the past when I've rewritten, sometimes it redirects from for example /streams/thread/1 to /streams/post.php?id= and sometimes it actually displays /streams/thread/1 in the URL, I would like it to display /streams/thread/1 in the URL, not just redirect.

like image 976
Odin Avatar asked Feb 17 '26 16:02

Odin


1 Answers

You can put your htaccess in root or streams folder (that's up to you).

In root folder

RewriteEngine On
RewriteBase /

RewriteCond %{THE_REQUEST} \s/streams/post\.php\?id=([0-9]*)\s [NC]
RewriteRule . streams/thread/%1? [R=301,L]

RewriteRule ^streams/thread/([0-9]+)$ streams/post.php?id=$1 [L]

In streams folder

RewriteEngine On
RewriteBase /streams/

RewriteCond %{THE_REQUEST} \s/streams/post\.php\?id=([0-9]*)\s [NC]
RewriteRule . thread/%1? [R=301,L]

RewriteRule ^thread/([0-9]+)$ post.php?id=$1 [L]
like image 133
Justin Iurman Avatar answered Feb 21 '26 14:02

Justin Iurman



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!