MAMP htaccess rewrite - .htaccess

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]

Related

htaccess url redirects with url contains = something

I want to create some userfriendly new redirects for my website.
My internal search pattern is the following : website.com/search/stuff
I want to add in my htaccess a rule that would redirect : /search=stuff
to : /search/stuff
I was trying the following code into my htaccess file :
RewriteCond %{QUERY_STRING} \\search=([^&]+) [NC]
RewriteRule ^$ /search/%1/? [NC,R,L]
But that doesnt seem to work... any ideas of where I may be wrong?
Thanks !

.htaccess redirect to subdomain with regex

I want to 301 redirect a specific path to another subdomain with htaccess
I want :
A : http://www.example.org/markets/access/id/56
B : http://www.example.org/markets/market/id/56
to redirect to :
A : https://archive.example.org/markets/access/id/56
B : https://archive.example.org/markets/market/id/56
I have tried this but get an error 500:
RewriteCond http://www.example.org/markets/(.+?)
RewriteRule https://archive.example.org/markets/$1 [R=301,L]
Thank you
Based on your shown samples, could you please try following. Please make sure you put these rules at the top of your .htaccess file.
Also make sure you clear your browser cache before testing your URLs.
RewriteEngine ON
RewriteCond %{HTTP_HOST} ^www\.(example\.org)$ [NC]
RewriteRule ^ https://archive.%1%{REQUEST_URI} [NE,R=301,L]

URL Redirect .htaccess to remove a directory

I would like to write a rule to redirect that kind or URL :
https://www.mywebsite.com/blog/wp-content/uploads/2007/06/DSC_1690.jpg
TO
https://www.mywebsite.com/wp-content/uploads/2007/06/DSC_1690.jpg
without the blog directory but ONLY for /blog/wp-content, i don't want to remove the /blog enretirely, because there is the blog here. i just want to move the wp-content at the root folder.
for all files inside /blog/wp-content to /wp-content
i tried that rule but it doesn't work : RewriteRule ^blog/wp-content/(.*)$ wp-content/$1 [L,NC,R]
Thanks for your help
Try this :
RewriteEngine On
RewriteCond %{THE_REQUEST} ^[A-Z]{3,}\s/blog/(wp-content/)(.+)\sHTTP.*$
RewriteRule ^blog/wp-content/(.*)$ /%1$1 [L,R=301]
RewriteRule ^wp-content/(.*)$ /blog/wp-content/$1 [L,NE]
With rules above , you will be able to hide /blog/wp-content from URI but still get the same path internally.
Clear browser cache then test

change path by RewriteRule

I want to open this url:
http://www.example.com/quiz/en/my-love/123232
and show:
http://www.example.com/quiz/en/my-love?result=123232
how to do it by .htaccess and RewriteRule?
The first answer of google about this :
Redirect 301 /oldfile.htm /newfile.htm
EDIT
Sorry, it wouldn't work in your case, you are right.
I think you could take a look at this one : htaccess 301 redirect issue with url variables
Or for docs :
github .htaccess
Apache documentation mod_rewrite
RE-EDIT
Following the documentation :
RewriteRule ^/quiz/en/my-love?result=([^/d]+)/?$ quiz/en/my-love/$1 [L,QSA]
/!\ not tested
try this inform if any issue.
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^([a-z]+)/([a-z]+)/([a-zA-Z-]+)/(\d+)$ $1/$2/$3.php?result=$4

how to Rewrite Single Page url in .htaccess

I need to rewrite only 1 specific URL
from
http://www.domainname.com/index.php?route=payment/axis/callback
to
http://www.domainname.com/payment/axis/callback
I tried these two from stack overflow, I don't know why its not working
1st one :
RewriteRule ^([A-Za-z0-9-]+)/?$ index.php?route=payment/axis/callback [NC,L]
2nd one :
RewriteRule ^index.php?route=payment/axis/callback payment/axis/callback [L]
Try this:
4) Rewriting yoursite.com/user.php?username=xyz to yoursite.com/xyz
Have you checked zorpia.com.If you type http://zorpia.com/roshanbh233 in browser you can see my profile over there. If you want to do the same kind of redirection i.e http://yoursite.com/xyz to http://yoursite.com/user.php?username=xyz then you can add the following code to the .htaccess file.
RewriteEngine On
RewriteRule ^([a-zA-Z0-9_-]+)$ user.php?username=$1
RewriteRule ^([a-zA-Z0-9_-]+)/$ user.php?username=$1
See the full page here.
Hope it helps!
I wouldn't use .htaccess with RewriteRule, since there are often problems with it. A simple workaround (with PHP redirect):
<?php
if($_GET['route'] == 'payment/axis/callback') {
header("Location: http://www.domainname.com/payment/axis/callback");
}
?>
You can either use h0ch5tr4355's workaround or you can try this:
RewriteEngine on
RewriteCond %{QUERY_STRING} ^route=payment/axis/callback$
RewriteCond %{SCRIPT_FILENAME} index.php
RewriteRule (.*) /payment/axis/callback [NC,QSD]
If you instead of a rewrite would like it to redirect to the new url you can add R=301 to the flags of the RewriteRule.

Resources