Htaccess interception in subfolder with parameters

I am trying to rewrite /streams/post.php?id=1

in /streams/thread/1

.

I found codes for .htaccess with parameters, but it didn't work in the subfolder.

Also , should I put another .htaccess in a subfolder, or use the one in 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 renders /streams/thread/1

in the url, I would like it to render /streams/thread/1

in the url, not just a redirect.

+3


source to share


1 answer


You can put your htaccess in the root folder or streams

(it's up to you).

In the 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 the folder with streams

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]

      

+2


source







All Articles