Rewrite URL with parameter - .htaccess

I would like to rewrite this URL:
https://example.com/forms/cus_F8fylX6aITpJOR
to
https://example.com/assets/forms/redirect.php?id=cus_F8fylX6aITpJOR
Here what I tried:
RewriteCond %{QUERY_STRING} id=(\w+) [NC]
RewriteRule ^assets/forms/redirect.php?id=$1 [L]
Where's my mistake ?
Thanks for any help.

Here what you'll need:
Options +FollowSymLinks
RewriteEngine On
RewriteRule ^forms/([^/]+) /assets/forms/redirect.php?id=$1 [QSA,L]

Related

htaccess 301 redirect joomla URLs with multiple variables

I'm trying to redirect this URL:
https://www.sendmoneypacific.org/index.php?option=com_countries&view=details&Itemid=165&lang=en
to this URL:
https://www.sendmoneypacific.org/pacific-communities/solomon-islands.html
I've tried the following:
RewriteEngine On
RewriteCond %{QUERY_STRING} ^option=com_countries&view=details&Itemid=165&lang=en$
RewriteRule ^/index.php$ https://www.sendmoneypacific.org/pacific-communities/solomon-islands.html? [R=301,L]
and:
RewriteEngine On
RewriteCond %{REQUEST_URI} ^/index.php$
RewriteCond %{QUERY_STRING} ^option=com_countries&view=details&Itemid=165&lang=en$
RewriteRule ^(.*)$ https://www.sendmoneypacific.org/pacific-communities/solomon-islands.html? [R=301,L]
But neither work. Any help would be greatly appreciated!
I figured it out -
## https://www.sendmoneypacific.org/index.php?option=com_countries&view=details&Itemid=165&lang=en
RewriteCond %{QUERY_STRING} ^option\=com_countries&view\=details&Itemid\=165&lang\=en$
RewriteRule ^index\.php$ https://www.sendmoneypacific.org/pacific-communities/solomon-islands.html? [R=301,L]
If anyone else needs help with this

Friendly Url for .php?id=1

I have this url
www.mysite.com/proyecto.php?id=3
and want this type of url
www.mysite.com/proyecto/id/3
I remember using this kind of code but is not working, any idea please?
<ifModule mod_rewrite.c>
Options +FollowSymLinks
RewriteEngine on
RewriteRule proyecto/id/(.*)/ proyecto.php?id=$1
RewriteRule proyecto/id/(.*) proyecto.php?id=$1
RewriteRule ^([^\.]+)$ $1.php [NC,L]
ErrorDocument 404 /error404.php
</ifModule>
Finally I improved a bit and I did www.mysite.com/proyecto/1 width the following code in the .htaccess
Thanks for the help!
RewriteEngine On
RewriteRule ^proyecto/([0-9]+)/?$ proyecto.php?id=$1 [NC,L]
Your code sample looks very confusing and does not match your verbal description at all. If I got you right, this is main part you are looking for:
RewriteCond %{HTTP_HOST} ^www\.mysite\.com$
RewriteCond %{REQUEST_URI} !^proyecto/id/(\d+)/? [NC]
RewriteCond %{QUERY_STRING} ^id=(\d+) [NC]
RewriteRule ^.*$ proyecto/id/%1/? [NC,L,R=301]

removing url parameters from one url using .htaccess codes

I tried lot of combinations using available examples (.htaccess directives), but I couldn't able to achieve what I want. The problem is...
My actual URL is
http://localhost/smon2/custsms/index.php?p_mob=9886419001
What I want is
http://localhost/smon2/custsms/
Please help me in wrinting .htaccess code lines.
Thanks
I tried with few of the items below...
RewriteEngine On
RewriteCond %{QUERY_STRING} ^p_mob=1$
RewriteRule (.*) $1? [R=permanent]
RewriteEngine On
RewriteCond %{QUERY_STRING} "p_mob=" [NC]
RewriteRule (.*) /$1? [R=301,L]
RewriteEngine On
RewriteRule ^/custsms/%{QUERY_STRING}/?$ http : //localhost/smon2/custsms/ [NC,L]
Nothing was working. please help.
Replace all your current rules with this rule:
DirectoryIndex index.php
RewriteEngine On
RewriteBase /smon2/
RewriteCond %{QUERY_STRING} ^p_mob=\d+ [NC]
RewriteRule ^(custsms)/index\.php$ $1/? [R=301,L,NC]

Redirecting with htaccess

It seems a very eask task, but I couldn't make it for hours after reading too much tutorial. Please help..
I need to redirect
http://example.com/myfolder/myfile.php?type=1&add=20
to this address:
http://example.com/newfolder/mytasks.xml
I tried too many. My last tryout was this:
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteRule ^/myfolder/myfile.php?type=1&add=20$ /newfolder/mytasks.xml [R=301,NC,L]
</IfModule>
Use this rule instead:
RewriteCond %{THE_REQUEST} ^[A-Z]{3,}\s/+myfolder/myfile\.php\?type=1&add=20 [NC]
RewriteRule ^ /newfolder/mytasks.xml [R=301,L]
Remember:
RewriteRule match doesn't start with a slash /
RewriteRule doesn't match query string, it matches only Request URI
If you also want the query type=1&add=20 removed, something like this should work:
Options +FollowSymLinks -MultiViews
RewriteEngine On
RewriteBase /
RewriteCond %{QUERY_STRING} type=1&add=20 [NC]
RewriteCond %{REQUEST_URI} !/newfolder/ [NC]
RewriteRule ^myfolder/myfile\.php /newfolder/mytasks.xml? [R=301,NC,L]
Redirects:
http://example.com/myfolder/myfile.php?type=1&add=20 to
http://example.com/newfolder/mytasks.xml
For silent mapping, replace [R=301,NC,L] with [NC,L]

Having issues redirecting in .htaccess

With .htaccess how can i redirect:
http://localhost/mvc_md/index.php/welcome/destroy
to
http://localhost/mvc_md/welcome/destroy
I'm currently using this and it isnt working:
RewriteEngine on
RewriteCond %{HTTP_HOST} ^localhost/mvc_md/$
RewriteRule ^(.*) localhost/$1 [QSA,L,R=301]
Options +FollowSymLinks
RewriteEngine on
RewriteRule ^([a-zA-Z]*)/?([a-zA-Z]*)?/?([a-zA-Z0-9]*)?/?$ index.php/$1/$2/$3 [NC,L]

Resources