I have redirect dynamic URL's which I'd like to redirect (301).
Link type 1
OLD - /?mainPage=Contact
NEW - /Contact
Link type 2
OLD - /?mainPage=Shows&show=circus
NEW - /shows/circus
How to do this?
To achieve that URL, you can use the following rule in your .htaccess:
RewriteEngine On
RewriteRule ^([^/]*)/([^/]*)$ /?mainPage=$1&show=$2 [L]
Make sure you clear your cache before you test this.
To redirect a URL using a query:
RewriteCond %{QUERY_STRING} mainPage=Optredens&show=petitcirque$
RewriteRule (.*) /shows/le-petit-cirque/? [R=301,L]
Related
Part of my .htaccess code is as follows:
RewriteRule ^([A-Z]+)*$ nextlevels_state.php?state=$1 [L]
RewriteRule ^([A-Z]+)*/([0-9]+)$ nextlevels_state.php?state=$1&page=$2 [NC]
This basically redirects URL, example.com/XX to example.com/nextlevels_state.php?state=XX and example.com/XX/1 to example.com/nextlevels_state.php?state=XX&page=1 (internally).
Now, I would like to change the URL structure of the URL from example.com/XX to example.com/nextlevels/XX and example.com/XX/1 to example.com/nextlevels/XX/1
and I tried changing .htaccess to as follows:
RewriteRule ^nextlevels/([A-Z]+)*$ nextlevels_state.php?state=$1 [L]
RewriteRule ^nextlevels/([A-Z]+)*/([0-9]+)$ nextlevels_state.php?state=$1&page=$2 [NC]
However, as the site urls are already indexed in search engines, I would like to know a way to redirect all the traffic from example.com/XX to example.com/nextlevels/XX (externally) using .htaccess .
Please guide me in this regard. Thank you community :)
Could you please try following, written and tested with shown samples only(improving your already done attempts here). Please make sure to clear your browser cache before testing your URLs.
RewriteEngine ON
##Rule for redirect to url example.com/nextlevels/XX.
RewriteRule ^([A-Z]+)$ nextlevels/$1 [R=301]
RewriteRule ^nextlevels/([A-Z]+)/?$ nextlevels_state.php?state=$1 [NC,L]
##Rule for redirect to url example.com/nextlevels/XX/1.
RewriteRule ^([A-Z]+)*/([0-9]+)$ nextlevels/$1/$2 [R=301]
RewriteRule ^nextlevels/([A-Z]+)*/([0-9]+)$ nextlevels_state.php?state=$1&page=$2 [NC,L]
With RewriteRule I've always cleaned my URLs as following:
RewriteRule ^page/(.*)$ page.php?urlkey=$1 [QSA]
My new host doesn't allow me to use Options +FollowSymLinks and therefore I cannot use the / anymore. So I've changed my RewriteRule to:
RewriteRule ^page-(.*)$ page.php?urlkey=$1 [QSA]
However, I need to redirect all my former URLs to the new version. I tried doing this using the following rule:
RewriteRule ^page/(.*)$ page-(.*)$ [R=301,L]
This is however not working. I've also tried to just make a Redirect in my .htaccess:
Redirect 301 https://www.example.com/page/urlkey https://www.example.com/page-urlkey
This is also not working.
EDIT
As requested the actual code below:
RewriteEngine on
RewriteRule ^citywalk-(.*)$ citywalk.php?urlkey=$1 [QSA]
RewriteRule ^citywalk/(.*)$ citywalk-(.*)$ [R=301,L]
For example the citywalk The Historical Centre has a urlkey the-historical-centre. The old url is citywalk/the-historical-centre.
To test this specific case and other technique:
Redirect 301 /citywalk/the-historical-centre https://example.com/citywalk-the-historical-centre
By visiting https://example.com/citywalk/the-historical-centre no redirecting takes place (the url stays the same in the browser) and no urlkey is found.
I need to redirect old domain to new with .htaccess
Situation:
www.oldodmain.com/en/categoryA/product1
www.newdomain.com/en/categoryB
Result I am trying to achieve
www.newdomain.com/en/categoryB/categoryA/product1
Tried to do with this code:
RewriteEngine On
RewriteBase /
RewriteCond %{HTTP_HOST} ^(www\.)?voniospasaulis\.lt$ [NC]
RewriteRule ^.+$ http://www.visaslabas.lt/lt/vonios-iranga/%{REQUEST_URI} [L,R=301]
But I get a result as follow:
www.newdomain.com/en/categoryB/en/categoryA/product1
I need to get rid of /en/before/categoryA to get url like this:
www.newdomain.com/en/categoryB/categoryA/product1
Your rule pattern has to start with en/ and should capture value after en/ in $1 that you can use in target:
RewriteEngine On
RewriteBase /
RewriteCond %{HTTP_HOST} ^(?:www\.)?oldodmain\.com$ [NC]
RewriteRule ^en/(.+)$ http://www.newdomain.com/en/categoryB/$1 [L,NE,NC,R=301]
Also note that I have answered using dummy domain names instead of your actual domain names shown in question.
Make sure to clear your browser cache or use a new browser for testing.
I need to Rewrite the old urls generated by ISS to a new system we have build (Joomla).
The url's had to be google friendly. What we want to happen:
Rewrite http://example.com/test.asp?index=3 to http://example.com/about
I've used a few Rewrite's i knew, but they dont work:
RewriteRule ^/test.asp?index=3 / [R=301,L]
RewriteRule ^/test.asp?index(.*)3 / [R=301,L
What pice of code am i missing/doeing wrong?
Kind regards.
You must use QUERY_STRING to check query string.
You can use this code in your htaccess (in document root folder)
RewriteEngine On
RewriteCond %{QUERY_STRING} ^index=3$ [NC]
RewriteRule ^test\.asp$ /about [R=301,L]
Note: put this rule before Joomla's rules
Currently what is happening is people are accessing old URLs from google like icpaweb.com/site/pages/about-us/ and being sent to their corresponding urls on icpaweb.org : icpaweb.org/site/pages/about-us.
What I want is to send people from: icpaweb.com/site/pages/about-us to icpaweb.org/ without any of the succeeding url segments.
How do I do this?
If you have to use an .htaccess file, you can use mod_rewrite:
RewriteEngine On
RewriteCond %{HTTP_HOST} icpaweb.com$ [NC]
RewriteRule .* http://icpaweb.org/ [R=301,L]
That will 301 redirect all requests for icpaweb.com to the index root of icpaweb.org. If you don't want 301, it can just be R.
You'll need to replace or turn off whatever mechanism is doing your redirecting now, they may not be compatible.
Use an url rewrite rule.
2 steps:
Write a RewriteCond so that the following rewrite rule only apply for url with host being icpaweb.com like RewriteCond %{HTTP_HOST} icpaweb.com$ [NC] The [NC] is for case insensitive match
Write a rewrite rule that convert all input to what you want like RewriteRule ^.*$ http://icpaweb.org/ [L]The [L] is to stop the rewriting to this rule if rule executed.