Redirect this url permanently with .htaccess - .htaccess

I am trying to permanently redirect a url but it doesn't seem to work, this is what I have in the .htaccess file
RewriteEngine on
rewriteRule ^modules\.php?name=My_Page$ http://mysite.net/mypage [R=permanent,L]
As you can see I want to redirect modules.php?name=My_Page to http://mysite.net/mypage
I appreciate any help. Thanks

The path used in RewriteRule doesn't contain the querystring. Use
RewriteEngine on
RewriteBase /
RewriteCond %{QUERY_STRING} ^name=My_Page$
rewriteRule ^modules\.php$ /mypage? [R=permanent,L]

Related

Seo friendly url - Unable to find a way to get the htaccess to rewrite the urls

Currently, my site has this url format:
https://example.com/blog/news.php?read=article-title-here
I would like to change this url to:
https://example.com/news/article-title-here
Any idea how to do this please? I tried this method but see no changes in the browser bar(even after emptying the cache):
RewriteCond %{QUERY_STRING} ^read=(.*)$
RewriteRule ^news/?$ %1.php? [R=301,L]
Also, where should the htaccess file be written?
in https://example.com/
or
https://example.com/blog/
Thank you in advance!
Ben
You can use in your https://example.com/.htaccess:
Options -MultiViews
RewriteEngine on
RewriteBase /
# external redirect from actual URL to pretty one
RewriteCond %{THE_REQUEST} \s/+blog/news\.php\?read=([^\s&]+) [NC]
RewriteRule ^ /news/%1? [R=301,L,NE]
# internal forward from pretty URL to actual one
RewriteRule ^news/(.+?)/?$ blog/news.php?read=$1 [L,QSA,NC]

Htaccess Redirect issues in joomla

Please help me with a redirect issue.
I am trying to redirect from http://www.project/index.php/blog to http://www.project/blog.
I tried the following but it did not work
RewriteRule ^(blog)$ ./index.php/ [L]
Give this a try:
Options +FollowSymlinks
RewriteEngine on
Rewriterule ^index.php/blog(.*)$ http://www.project/blog$1 [r=301,nc]
If you want to append the requested path info at index.php, you might use this RewriteRule
RewriteCond %{REQUEST_URI} !^/index\.php
RewriteRule ^ /index.php%{REQUEST_URI} [L]

Redirect duplicate urls in htaccess

I have a big list of duplicate urls and i need to do some redirect
Example
www.mysite.com/mypage/name2_68.html
www.mysite.com/jjj/name2_68.html
www.mysite.com/aa/name2_68.html
www.mysite.com/5654/name2_68.html
www.mysite.com/mypage/myname87.html
www.mysite.com/6584/myname87.html
www.mysite.com/any-number/myname87.html
www.mysite.com/any_word/myname87.html
All i need to do is to redirect them to
www.mysite.com/mypage/myname87.html
www.mysite.com/mypage/name2_68.html
So all url with
www.mysite.com/anycharactere/example1.html
Will be redirect to
www.mysite.com/mypage/example1.html
This should work.
RewriteEngine on
RewriteBase /
RewriteCond %{REQUEST_URI} !^/mypage/?
RewriteRule ^[^/]+/(.*\.html?)$ /mypage/$1 [R=301,L]
Put it in your .htaccess
RewriteEngine On
RewriteRule .*/([^/]+.html)$ /mypage/$1

htacess redirect if url stops with specific word

Is it possible to redirect based on an url that would be as:
www.url.com/stuff.php
But not redirect if the url contained any characters after the php, as such:
www.url.com/stuff.php?variables=values&othervariable=othervalue&etc=more
I have no clue how to wriite this either.
Thanks in advance!
Edit: basically I need the redirect to happen to www.url2.com only if www.url.com ends with .php, but not if the .php is followed by variables.
try
RewriteCond %{QUERY_STRING} ^$
RewriteRule ^/site.com/?$ /site.com/cart.php [R=301,NC,L]
Try:
RewriteEngine On
RewriteCond %{QUERY_STRING} ^$
RewriteRule ^/?cart.php$ / [L,R=301]
Options +FollowSymlinks
RewriteEngine on
RewriteRule ^stuff.php$ RELATIVE_OR_ABSOLUTE_URL_HERE [L]

htaccess redirection help needed

I have a dynamic url domain.com/product/Paper_Bags/Merchandise_Bags_-_Matte_Colors/6_25__X_9_25_/Misty_Grey?7. Which when called need to redirect to domain.com/paper-merchandise-bags-plain-white/
I am using the condition and the rule as
RewriteCond %{QUERY_STRING} (.*)$
RewriteRule ^(.*)/Misty_Grey http://domain.com/paper-merchandise-bags-plain-white/? [R=301,L]
But its not working. Can Someone help me to solve this issue.
If i use RedirectMatch ^(.*)/Misty_Grey http://domain.com/paper-merchandise-bags-plain-white/
Its getting redirected to http://domain.com/paper-merchandise-bags-plain-white/?7
Is there any way to remove the ?7 so tha the querystring will not be visible
Try the following commands,
//Rewrite to www
Options +FollowSymLinks
RewriteEngine on
RewriteCond %{HTTP_HOST} ^domain.com[nc]
RewriteRule ^(.*)$ http://www.domain.com/$1 [r=301,nc]
//301 Redirect Old File
Redirect 301 http://domain.com/product/Paper_Bags/Merchandise_Bags_-_Matte_Colors/6_25__X_9_25_/Misty_Grey?7 http://domain.com/paper-merchandise-bags-plain-white/?

Resources