Htaccess rewrite in subfolder with parameters - .htaccess

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.

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]

Related

How to make redirect in htaccess except for one folder and its directories and files inside and one path for cms Joomla

How to perform redirection in .htaccess file except for one folder and its directories and files inside and one path
I would like to perform the redirect as follows
from domain
www.olddomain.org
www.olddomain.org/^ (any path)
to the domain:
www.newdomain.org
www.newdomain.org/^ (any path)
BUT except for
www.olddomain.org/administrator/test/test1/test2
www.olddomain.org/administrator/ (any path)
AND
www.olddomain.org/test-article
I would like to add that I want to make these redirects for the Joomla 3 CMS system
I try:
RewriteEngine On
RewriteBase /
RewriteCond %{HTTP_HOST} ^olddomain.pl
#redirect them to new-example
RewriteCond %{REQUEST_URI} !=/administrator/^
RewriteCond %{REQUEST_URI} !=/testarticle
RewriteRule (.*) https://newdomain.pl/$1 [R=301,L]
and
RewriteEngine On
RewriteCond %{REQUEST_URI} !^/administrator.*/$ [NC]
RewriteRule .* https://www.newdomain.com/ [R=301,L]
But it doesn't work the way I want
Try this one:
RewriteEngine On
RedirectMatch 301 ^/((?!administrator).*)$ http://newdomain.org/$1

RewriteRule php to html extension

how to write RewriteRule to access php file as html extension, the mark file is located inside folder called domain.com/markfolder/mark.php
and i got following in my root directory
Options +FollowSymlinks
RewriteEngine On
RewriteBase /
RedirectMatch 301 (.*)\.html$ $1.php
and below file i try to locate inside domain.com/markfolder/.htaccess
try 1
RewriteEngine on
RewriteRule ^mark\.php$ mark.html [NC,R]
try 2
RewriteEngine on
RewriteRule ^(.*)\.html $1\.php
try 3
Options +FollowSymlinks
RewriteEngine On
RewriteRule ^(.+)\.html$ $1.php [NC,L]
above three try simple doesn't work.
First, your htaccess file in your root directory is causing the problem. It's redirecting .html to .php and is part of mod_alias, not mod_rewrite. This means requests will get processed by both the RedirectMatch as well as any rewrite rules. So first change your root htaccess to:
Options +FollowSymlinks
RewriteEngine On
RewriteBase /
RewriteRule ^(.*)\.html$ $1.php [L,R=301]
Not sure why you want to permanently redirect, since this will affect all requests even requests in subdirectories. It seems like it's not what you want and will only break any attempt for you to rewrite.
Then in the htaccess file in your markfolder:
RewriteEngine On
RewriteRule ^(.*)\.html$ $1.php [L]

htaccess redirect subfolder

I would like to redirect the url http://intranet/trac/paradox/report/6 to http://cobra.woking/trac/paradox/report/6. trac is a subfolder and paradox is a subfolder. report/6 are params that need to be kept and may change.
In my apache doc root i have
#/opt/html/.htaccess
Redirect 301 / http://intranet/intranet
RewriteEngine On
RewriteRule ^trac/paradox/report/6$ http://cobra.woking/trac/paradox/report/6 [L,R]
I have tried the following which does not work
Options +FollowSymLinks
RewriteEngine On
RewriteCond %{HTTP_HOST} !^intranet$
RewriteRule (.*) http://cobra.woking/$1 [R=301,L]
RewriteCond %{HTTP_HOST} !^intranet$
RewriteRule (.*) http://cobra.woking/$1 [R=301,L]
URL i want to change is http://intranet/trac/paradox/ to http://cobra.woking/trac/paradox/. I have placed .htaccess in the /opt/html/trac/paradox/.htaccess
In the htaccess file of your intranet's document root, add this to the top of the file:
RewriteEngine On
RewriteRule ^trac/paradox/report/6$ http://cobra.woking/trac/paradox/report/6 [L,R]

Redirect url with .htaccess

I m sure that many people will say that this is duplicated but I try everything from other "Question"`s and nothings work for me.
The problem is that I move my project to the web server.
In this server I have folder "public_html" where I but my project Symfony.
Now to enter on my project I must write the following url: www.mydomain.com/Symfony/web/*
But I want to write a Rewrite Rule which will redirect from www.mydomain.com/Symfony/web/* to
www.mydomain.com/home/*.
To do this I try on 2 different ways with many combination of ReWrite rule.
In my public_html I create a .htaccess folder
I edit the .htaccess in Symfony/web folder
I add the following rule in both file but without success
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^Symfony/web/(.*)$ www.mydomain.com/home/$1 [L,R=301]
Unfortunately without success. What I`m doing wrong?
My htaccess file look like
And all the time Error 404 Object not found
Symfony/web/.htaccess
DirectoryIndex app.php
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /Symfony/web/
RewriteCond %{THE_REQUEST} \s/+Symfony/web/ [NC]
RewriteRule ^(.*)$ /home/$1 [L,R=301]
RewriteRule ^home/(.*)$ $1 [L,NC]
</IfModule>
It`s redirecting me but I receive again Object not found :(
I delete the .htaccess in public_html folder which is the root one for my server
public_html\.htaccess
RewriteEngine On
RewriteRule ^home/(.*)$ /Symfony/web/$1 [L,NC]
1: Place this code in /Symfony/web/.htaccess:
RewriteEngine On
RewriteBase /Symfony/web/
RewriteCond %{THE_REQUEST} \s/+Symfony/web/ [NC]
RewriteRule ^(.*)$ /home/$1 [L,R=301]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)$ app.php [L]
2: Place this code in /public_html/.htaccess:
RewriteRule ^home/(.*)$ /Symfony/web/$1 [L,NC]
I'm going to go out on a limb and say that your rule is backwards. I think you want your URL to be www.mydomain.com/home/* in the browser... In which case the rule would be reversed. Also, your .htaccess should be in the root and you don't need to include the domain in the rewrite rule because you set a rewrite base.
RewriteRule ^home/(.*)$ Symfony/web/$1 [L,R=301]

htaccess and rewriting urls

currently i have a /en/ folder that is empty except for a .htaccess with the following
Options +FollowSymlinks
RewriteEngine on
RewriteRule ^(.*)$ ../index.php?language=en$1 [NC]
i use it to eliminate the need for
index.php?language=en
in all my URLs. I would like to modify the htaccess in a way that i no longer need the /en/ folder with nothing but the htaccess inside. ideally i would like an htaccess in my root folder that reads the url and if it is www.example.com/en/ to rewrite to www.example.com/index.php?language=en
This should work for you:
RewriteRule ^en/(.*)$ index.php?language=en$1 [NC]
Put the following code in .htaccess file in your root folder.
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^en/(.*)$ index.php?language=en$1 [L]
Here $1 will append rest of the url as well. The condition will also help if you request your files using direct url.

Resources