Rewrite Rules different filename same redirection - .htaccess

I would like to have something like that in .htaccess:
^Test/filename/param --> mydirectory/test.php?id=$1
The filename can be different each time but the redirection will always be the same. Only the parameter will change.
I would be very grateful if you could help me because I'm very confused.
Thanks in advance

use regular expressions:
RewriteEngine on
RewriteCond %{SCRIPT_FILENAME} !-f
RewriteRule folder/(.*)$ folder/test.php?id=$1
also may be cache problem and try it in incognito mode.

Related

How do a I remove a specific query string in htaccess?

Hello and thanks in advance...
I have a situation where I need to completely remove the query string if it matches a pattern. I've been searching for an answer or even something close. So far, no luck. I've even tried a few things in my htaccess but without success.
The specific query string I need to remove is ?fbclid= and everything that comes after it.
Thank you!
Hard to say what your actual issue is, since you did not share your attempts so far. So we cannot help with those. All I can offer is another example. No idea if that helps.
This implements an internal rewrite:
RewriteEngine on
RewriteCond %{QUERY_STRING} ^fbclid=
RewriteRule ^ %{REQUEST_URI} [QSD]
Here the variant for an external redirection:
RewriteEngine on
RewriteCond %{QUERY_STRING} ^fbclid=
RewriteRule ^ %{REQUEST_URI} [QSD,R=301]
It always is a good idea to start out with a temporary 302 redirection and to only change that to a 301 once you are sure the current solution is final.

Redirect URL changing QUERY string parameter ? to & with .htaccess

I am trying to change this url:
http://blabla.nl/download/?url=https://www.bla.com/see?v=345345&type=download
to this:
http://blabla.nl/download/?url=https://www.bla.com/see&v=345345&type=download
Using .htaccess
so the ? needs to change to an &.
at the moment i am not very succesfull fixing this.
You have to do it this way:
RewriteEngine On
RewriteBase /
RewriteCond %{QUERY_STRING} ^(url=https://www\.youtube\.com/watch)\?(v=[A-Za-z0-9]+&type=downloa‌​d)
RewriteRule ^/?8/downloadff/?$ /8/downloadff/?%1&%2 [R=301,NC,L]
I assume that the number 345345 is always a number an will be different all the times but the rest keeps the same.
Put this as .htaccess file on http://example.nl/ or http://example.nl/download/
Try this:
RewriteEngine On
RewriteRule ^download/?url=https://www.bla.com/see&v=345345&type=download/?$ download/?url=https://www.bla.com/see?v=345345&type=download [NC,L]
I hope it works for you.

mod_rewrite substitution not working

I'm having trouble with an Apache mod_rewrite. My .htaccess file is located in "/posts". Here's the contents:
RewriteEngine on
RewriteBase /
RewriteRule ^.*\.html$ ?url=/posts/2014/1215A.html [QSA]
The incoming request is for "/posts/2014/1214A.html". I want that request to be rewritten so as to be for, "/?url=/posts/2014/1215A.html". It appears that the regular expression is matched. The problem seems to be with the substitution. I've actually had the whole thing working; but, I must have somehow messed something up. Can anyone please tell me how to fix this? Thanks.
... doug
This should work :
RewriteEngine on
RewriteBase /posts/
RewriteCond %{REQUEST_URI} !^/posts/index
RewriteRule ^.*\.html$ ?url=/posts/2014/1215A.html [QSA]

How to mod-rewrite language parameter (e.g. ?lang=en) to fake subdomain (e.g. en.mydomain.com)?

It's so hard being a noob. I need someone to help me do this :-(
So basically, I need users to use this url:
en.mydomain.com <- very nice!
instead of using:
www.mydomain.com/index.php?lang=en
I know this is serious .htaccess stuff. Which I may never get my head around without any help. So, Thanks a lot.
You can place this rule as your very first rule in root .htaccess:
RewriteEngine On
RewriteCond %{QUERY_STRING} !(^|&)lang=en(&|$) [NC]
RewriteRule ^$ /index.php?lang=en [L,QSA]

.htaccess, get the value after a period and then redirect

I am trying to redirect a URL using a .htaccess file. The URL structure is like:
http://mydomain.com/folder/.anything_goes_here
Note the dot in the above Url. I want to remove it somehow using .htaccess.
I have tried using RewriteRule but it's not working.
Here is the code I used:
RewriteEngine on
RewriteBase /
RewriteRule ^/folder/.(.*+)/?$ /folder/$1 [L]
Any help would be highly appreciated. Thank you.
The period has a special meaning in regular expressions (it means "any character"). In order to explicitly specify a period, you need to escape it.
RewriteRule ^/folder/\.(.*+)/?$ /folder/$1 [L]

Resources