change path by RewriteRule - .htaccess

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

Related

force index.php in url with htaccess

I've spent the last two hours reading stackoverflow and the apache manual trying to find a solution to this, but haven't found any, if a directory is access (http://domain.ext) I'd like to force index.php to appear in the url (http://domain.ext/index.php) if possible.
If anyone could help I'd really appreciate it, thank you.
RewriteEngine on
RewriteRule index.php
you can use this:
RewriteEngine on
RewriteRule ^$ /index.php?
(but you will not see it in a browser because the rewrite engine just directs to the correct file/directory without changing the url from the browser)
with [R] tag you can redirect the user so the new url would appear in the browser
I've just found what works for me
RewriteEngine On
RewriteRule ^/?$ $1/folder/index.php$2 [R=301,L]

Replace part of a URL with .htaccess

I had to change the name of a subpage and now the problem is that all shared links on Facebook, Twitter, etc. are not working anymore.
That's why I am trying to redirect only a part of a URL with .htaccess but I have no solution yet.
It should work like this:
www.mydomain.com/feeds/details/ --> www.mydomain.com/highlights/details/
I hope you can help me!
It will depend on your server but you are looking for something along these lines
//Rewrite to www
Options +FollowSymLinks
RewriteEngine on
RewriteCond %{HTTP_HOST} ^example.com[nc]
RewriteRule ^(.*)$ http://www.example.com/$1 [r=301,nc]
//301 Redirect Entire Directory
RedirectMatch 301 /feeds(.*) /highlights/$1
You can try rewriting the URL using RewriteRule, like follows:
.htaccess
RewriteEngine on
RewriteRule ^/feeds/details$ /highlights/details/
Hope, that works for you.
You can find more information here.
I took your tip and adjusted my reality.
My problem:
https://example.com/contact/example.com
My solution:
RedirectMatch 301 (.*)/example.com(.*) $1/$2
After solution, redirect:
https://example.com/contact/

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]

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.

Mod_Rewrite with .htaccess is not working

I just learnt about url-rewrite for my website with .htacess. My actual url is:
localhost/index.php?view=some-page
So i write this RewriteRule like this:
RewriteRule ^/([^/]*)/?$ /index.php?view=$1 [NC,L]
When i typed localhost/homepage on my browser, It does not work, it displays error 404 object not found. What have i done wrong please show me.
Many thanks
This should work in your DocumentRoot/.htaccess:
RewriteEngine On
RewriteBase /
RewriteRule ^([^/]+)/?$ index.php?view=$1 [QSA,L]
Leading slash is not matched in htaccess.
are you using apache?
This link from step 6 helped me
https://www.digitalocean.com/community/tutorials/how-to-install-wordpress-on-ubuntu-14-04
When i was playing around with rewrites i had to enable it and tell apache where the pages were stored

Resources