url redirection with get parameter Apatche htaccess - .htaccess

Hello I have a url that is like that :
www.mysite.com/activation.php?token=d4ba10b14dedc7e7e7338ee8251670fa
What I would like to have is something like that :
www.mysite.com/Activation/Token/d4ba10b14dedc7e7e7338ee8251670fa
How can I do that please

You can put this rule in your htaccess (which has to be in root folder)
RewriteEngine On
RewriteRule ^Activation/Token/([^/]+)$ /activation.php?token=$1 [L]

Related

Change name of subfolder and redirect

I have some links like this:
http://example.com/firstfolder/oldfolder/file1.html
http://example.com/firstfolder/oldfolder/file2.html
http://example.com/firstfolder/oldfolder/file3.html
http://example.com/firstfolder/oldfolder/file4.html
Now, the oldfolders name has changed to newfolder.
I want to rewrite and redirect all oldfolder to newfolder.
Means, if you open e.g.
http://example.com/firstfolder/oldfolder/file3.html
it should redirect to
http://example.com/firstfolder/newfolder/file3.html
I tried the following:
RewriteEngine On
RewriteRule ^oldfolder/(.*) /newfolder/$1 [R=301,NC,L]
Unfortunately this is doing nothing. There's no redirect. It's the same as before.
What am I doing wrong?
You can use Redirect directive to redirect your old folder uris to the new one :
Redirect 301 /firstfolder/oldfolder/ http://example.com/firstfolder/newfolder/
I find it odd that there is a "."in your url.
Otherwise in the htaccess you can try to add a "\" like this :
RewriteEngine On
RewriteRule ^old\.folder/(.*) /newfolder/$1 [R=301,NC,L]

MAMP htaccess rewrite

I'm using a .htaccess file for the first time with MAMP servor, and I'm trying to do something simple :
I want this link : http://localhost:8888/My_app/ redirect on : http://localhost:8888/My_app/Pages/ .
I did these on .htaccess file, located on /Application/MAMP/htdocs/My_app/ :
RewriteEngine On
RewriteRule ^$ http://localhost:8888/My_app/Pages [L,R=301]
This work, but it simply redirect the user. I want to see the first url http://localhost:8888/My_app/ and not http://localhost:8888/My_app/Pages in my browser, like a 'pointer' on this page, is it possible ?
Thanks !
Updated -
So it work great with this code :
RewriteEngine On
RewriteRule ^/?$ http://localhost:8888/My_app/Pages/ [L]
But I have forgotten something in my question, how to do the same for each file in this folder ? If I want http://localhost:8888/My_app/dashboard.php pointed on http://localhost:8888/My_app/Pages/dashboard.php ?
You can just use this rule:
RewriteEngine On
RewriteRule ^((?!Pages/).*)$ /Pages/$1 [L,NC]

URL rewriting in PHP using .htaccess: How to put `/` in URL?

I have a URL like www.test.com?id=other-flavor&pid=hannycakes.
I did above URL like www.test.com/other-flavor$pid=hannycakes using .Htaccess
but I need www.test.com/other-flavor/hannycakes.
For this If I use / in my URL it can take as a folder.
How resolve my problem. How to put / in URL?
Try this:
RewriteEngine On
RewriteRule ^([^/]*)/([^/]*)$ /?id=$1&pid=$2 [L]

Redirect only certain paths

I need to redirect only some pages to make the URL neater, such as:
Original : http://www.mywebsite.com/form.php
What I want : http://www.mywebsite.com/form AND http://www.mywebsite.com/form/
How do I write the htaccess file for that?
I have not tested but something like this should work:
RewriteEngine On
RewriteRule ^form.php(/)?$ http://www.mywebsite.com/form$1 [L]

How to rewrite an url without beening displayed the file extension

How i rewrite url, using htaccess , i have tryed like this :
RewriteRule ^file$ file.php [L]
i don't want to be displayed the file extension
i want to rewrite url like this :
http://example.com/file.php into http://example.com/file
RewriteEngine on
RewriteRule ^file$ /file.php

Resources