I add the code:
RedirectMatch 301 /san-pham/khuyen-mai/ /khuyen-mai
In default .htaccess file in opencart but the result will return:
http://myphamthiennhien.com/khuyen-mai?_route_=san-pham/khuyen-mai
You can test it here
http://myphamthiennhien.com/san-pham/khuyen-mai/
How can I solve it?
Use mod_rewrite to strip off query-string:
RewriteEngine On
RewriteRule ^san-pham/khuyen-mai/ /khuyen-mai? [L,R=301,NC]
Note ? in the end, that is required to strip query string.
Related
Going to show my lack of regex knowledge here but seem to be having trouble with the following:
I need to redirect the following example structure of a url:
www.example.com/blog-title-here/tags/this+is+a+long+tag+name
www.example.com/tag/this-is-a-long-tag-name
I need to redirect to just /tag and replace any instance of + with a -
You can use this recursive redirect rule as your very first rule in site root .htaccess:
RewriteEngine On
RewriteRule "(?:.*/)?(tag/[^ +]*)[ +]+([^ +]*[ +].*)$" $1-$2 [N,NC,DPI]
RewriteRule "(?:.*/)?(tag/[^ +]*)[ +]+([^ +]*)$" /$1-$2 [L,R=301,NC,NE]
This will redirect http://localhost/blog-title-here/tag/this+is+a+long+tag+name to http://localhost/tag/this-is-a-long-tag-name
RedirectPermanent /forum-old-f48.html /forum-neu-f1.html
301 Result:
forum-neu-f1.html?f=48&start=
Target: Dont append the "?f=48&start=" part. How can I make a stop behind the html?
The result should look like this:
forum-neu-f1.html
thank you!
To strip off query string you need to use mod_rewrite rule. Have this rule in root .htaccess:
RewriteEngine On
RewriteRule ^forum-old-f48\.html$ /forum-neu-f1.html? [L,NC,R=301]
You should test it after clearing your browser cache.
As part of a migration I need to redirect sections of a site.
The below RedirectMatch is working, but the query string is being carried across.
I have tried using a "?" in various ways to remove the original query string, but have been unable to get it to work.
Current RedirectMatch:
RedirectMatch 301 ^/store/match.*$ http://shop.domain.com/new-directory/
The above RedirectMatch turns this:
domain.com/store/match-something-something-c-536.html?osCsid=123456…
Into this:
shop.domain.com/new-directory/?cPath=536&osCsid=123456...
But I want:
shop.domain.com/new-directory/
You need to use mod_rewrite for this:
RewriteEngine On
RewriteRule ^store/match http://shop.domain.com/new-directory/? [R=301,L,NC]
I need to redirect the following URL (and NOTHING with additional URL paths after the wholesale) :
www.jedzebel.com/wholesale (or jedzebel.com/wholesale)
to the following :
www.jedzebel.com/wholesale-info/wholesale-information.html
Unfortunately, I have a folder called wholesale already and when a standard 301 redirect is in place the mod_rewrite rules are causing the all URL's with wholesale in the path to rewrite incorrectly.
I tried the following in both RedirectMatch and Redirect in .htaccess after the Joomla rewrite rules but I must have something wrong :
RedirectMatch (.*)/wholesale?$ http://www.jedzebel.com/wholesale-info/wholesale-information.html [R=301,L]
Redirect 301 ^wholesale?$ http://www.jedzebel.com/wholesale-info/wholesale-information.html
Any ideas ? I need to ONLY rewrite exactly www.jedzebel.com/wholesale ...
You can make trailing slash optional in your rule.
You can try this rule:
RedirectMatch 301 ^/wholesale/?$ /wholesale-info/wholesale-information.html
Alternative:
RewriteEngine On
RewriteRule ^wholesale/?$ /wholesale-info/wholesale-information.html [L,R=301,NC]
My goal is simply to redirect:
/jsn.php?parameters to http://www.site2.com/jsn.php?parameters
I tried with
Redirect permanent /jsn.php(.)* http://www.site2.com/jsn.php$1
Query string parameters are automatically passed, you simply want to do this:
Redirect permanent /jsn.php http://www.site2.com/jsn.php
The (.)* doesn't work with the Redirect directive, you were probably thinking of RedirectMatch, but either way, you don't need it. And also (.)* should be (.*), otherwise the $1 backreference would only get the first character.
Enable mod_rewrite and .htaccess through httpd.conf and then put this code in your .htaccess under DOCUMENT_ROOT directory:
Options +FollowSymLinks -MultiViews
# Turn mod_rewrite on
RewriteEngine On
RewriteBase /
RewriteRule ^(jsn\.php)$ http://www.site2.com/$1 [L,NC,R=301]
You can use an explicit URL rewrite in your .htaccess file:
RewriteRule ^/jsn\.php\?(.*) http://www.site2.com/jsn.php?$1 [R]
Note: You need to escape . and ? because they are also regular expression characters.
If you have a problem using mod_rewrite, post the contents of your file.