In my .htaccess I have this lines:
RewriteEngine On
RewriteCond %{http_host} ^test.ru [nc]
RewriteRule ^(.*)$ http://www.test.ru/$1 [r=301,nc]
RewriteBase /
RewriteRule ^(.*)/$ index.php?string=$1 [NC,L]
so I want to change test.ru to www.test.ru
and also to give www.test.ru/my_string_value/ to $_GET['string']
(for example from this URL www.test.ru/ru/pages/id/) , exploding this ru/pages/888 , getting my parameters (lang=ru, cat=pages, id=888).
When I'm trying to check www adding part (writing test.ru must make www.test.ru) geting this:
http://www.test.ru/index.php?string=http://www.test.ru
With parameters getting is ok!
And one interesting thing! After comenting lines
#RewriteEngine On
#RewriteCond %{http_host} ^test.ru [nc]
#RewriteRule ^(.*)$ http://www.test.ru/$1 [r=301,nc]
#RewriteBase /
#RewriteRule ^(.*)/$ index.php?string=$1 [NC,L]
getting the same thing!
What is wrong.
You have some things in the wrong order but you are probably cached. The browser will cache 301 redirects. Clear your browser cache or try in another browser. Also use 302 while testing. Then change to 301 when everything is working. And you should use the L flag on redirects as well.
RewriteEngine On
RewriteBase /
RewriteCond %{HTTP_HOST} ^test\.ru [NC]
RewriteRule ^(.*)$ http://www.test.ru/$1 [R=302,NC,L]
RewriteRule ^(.*)/?$ index.php?string=$1 [NC,L]
Related
my current htaccess is:-
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteCond %{HTTP_HOST} ^example\.com$ [NC]
RewriteRule ^(.*)$ http://www.example.com/$1 [L,R=301]
</IfModule>
i want to add rule to htaccess for url like https://www.example.com/abc/arg1/arg2 should redirect to http://www.example.com/abc/arg1/arg2
for this https://www.example.com/abc/* it should redirect to non-https format with keeping all arguments.
Use below rule, check after clearing your cache.
RewriteCond %{REQUEST_URI} ^/abc/(.*) [NC]
RewriteRule ^ http://www.%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
Edit: Please try with below rule,
RewriteCond %{REQUEST_URI} !^/abc/(.*) [NC]
RewriteRule ^ https://www.%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
In above rule we are appending https to all url which are not starting with abc/(.*) you have to use this rewritecond where your original https rule exists.
If you want to redirect all https requests starting with abc/ to http, you must check for both abc/ and HTTPS
RewriteCond %{HTTPS} on
RewriteRule ^abc/ http://www.example.com%{REQUEST_URI} [R,L]
When everything works as it should, you may replace R with R=301 (permanent redirect). Never test with R=301.
I am not sure how you achieve the job, but the following should be working perfectly for you.
RewriteCond %{HTTPS} on
RewriteCond %{REQUEST_URI} ^/abc [NC]
RewriteRule ^(.*)$ http://%{HTTP_HOST}%{REQUEST_URI} [R=301,L]
I'm trying to setup 301 redirections for a website that's build with Phalcon Framework.
The Problem
My redirection is working fine, but it's appending a ?_url= with the old url after the redirection.
Default .htaccess
Here's what comes with the Phalcon Framework in the .htaccess:
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)$ index.php?_url=/$1 [QSA,L]
Example
When a user is going on http://example.net/fr/le-circuit/a-propos, it's redirecting to http://example.net/fr/circuit?_url=/fr/le-circuit/a-propos
As you can see, the ?_url= is the extra that I'm trying to remove.
My .htaccess
Here's my .htaccess without the redirection:
AddDefaultCharset UTF-8
<IfModule mod_rewrite.c>
RewriteEngine On
# Redirection for old website links
RewriteCond %{HTTP:Accept-Language} ^fr [NC]
RewriteRule ^$ /fr/ [L,R=301]
RewriteCond %{HTTP:Accept-Language} ^en [NC]
RewriteRule ^$ /en/ [L,R=301]
RewriteRule ^$ /fr/ [L,R=301]
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)$ index.php?_url=/$1 [QSA,L]
</IfModule>
Attempt #1
I've tried the following Redirect directive before and after the default rewrite rules that came with Phalcon.
Redirect 301 /fr/le-circuit/a-propos /fr/circuit
Attempt #2
I thought my first attempt wasn't strict enough so I decided to use regex and RedirectMatch:
RedirectMatch 301 ^/fr/le-circuit/a-propos/?$ /fr/circuit
Just like before, I've tried it before and after the rules that came with Phalcon and it's appending the old url after the redirection.
Attempt #3
I've tried to hardcode the url in the redirection to see if the ?_url= would still append and ... yes it does.
RewriteMatch 301 ^/fr/le-circuit/a-propos/?$ http://example.net/fr/circuit
Does anyone know the problem or have an idea why it's appending the old url after the redirection?
Keep redirect rules before your other rules:
RewriteEngine On
# Redirection for old website links
RewriteRule ^fr/le-circuit/a-propos/?$ http://example.net/fr/circuit [L,NC,R=301]
RewriteCond %{HTTP:Accept-Language} ^fr [NC]
RewriteRule ^$ /fr/ [L,R=301]
RewriteCond %{HTTP:Accept-Language} ^en [NC]
RewriteRule ^$ /en/ [L,R=301]
RewriteRule ^$ /fr/ [L,R=301]
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)$ index.php?_url=/$1 [QSA,L]
Make sure to clear your browser cache while testing this change.
Make sure you clear your cache when working with 301 permanent redirects. Always debug them as 302 temporary redirects. Make sure your cache clearing prevents the redirection from happening when you comment out the redirects in your .htaccess file. Once you've done that, you can try the following suggestion:
Ditch the "_url" altogether by using REQUEST_URI from your bootstrap instead:
Use RewriteRule .* index.php [L] instead of: RewriteRule ^(.*)$ index.php?_url=/$1 [QSA,L]
Then use this line in your index.php bootstrap:
echo $application->handle(strtok($_SERVER["REQUEST_URI"],'?'))->getContent();
Rather than echo $application->handle()->getContent(); which defaults to handle $_GET['_url'].
I want to redirect both
https://website.me/ and https://www.website.me/ to https://es.website.me/
This rule doesn't work
RewriteCond %{HTTPS} !^on$
RewriteRule (.*) https://es.website.me/$1 [R,L]
Use below htaccess
RewriteEngine on
RewriteCond %{HTTP_HOST} ^(www\.)?website\.me$ [NC]
RewriteRule ^(.*)$ https://es.website.me/$1 [R=301,L]
Try this one for redirection in your case:
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{HTTP_HOST} ^website.me$ [OR]
RewriteCond %{HTTP_HOST} ^www.website.me$
RewriteRule (.*)$ https://es.website.me/$1 [R=301,L]
</IfModule>
Do you want to redirect, or rewrite?
To redirect with a code 301 (permanently moved), make 2 virtual hosts; one for the real site, and one for all the URL's you want to redirect. In the redirect host, add this line:
Redirect 301 / https://es.website.me/
Since you want to redirect only if HTTPS is already used, you must check for it, together with the hostname of course.
RewriteCond %{HTTPS} on
RewriteCond %{HTTP_HOST} ^(www\.)?website\.me$ [NC]
RewriteRule ^ https://es.website.me%{REQUEST_URI} [R,L]
When everything works as it should, you may replace R with R=301. Never test with R=301.
My .htaccess file looks like this:
RewriteEngine on
RewriteBase /
RewriteCond %{HTTP_HOST} ^www\.mywebsite\.com [NC]
RewriteRule ^(.*)$ http://mywebsite.com/$1 [L,R=301]
RewriteCond %{HTTPS} !on
RewriteRule (.*) https://%{HTTP_HOST}%{REQUEST_URI}
RewriteRule ^resources/([^/\.]+)/?$ page.php?theme=resources&pg=$1 [L]
RewriteRule ^resources/([^/\.]+)/?/([^/\.]+)/?$ page.php?theme=resources&pg=resources&catname=$1&cat=$2 [L]
RewriteRule ^resources/([^/\.]+)/?/([^/\.]+)/?/([^/\.]+)/?$ page.php?theme=resources&catname=$1&cat=$2&pg=$3 [L]
RewriteRule ^albums/([^/\.]+)/?/([^/\.]+)/?$ page.php?theme=albums&pg=albums&albumname=$1&album=$2 [L]
RewriteRule ^albums/([^/\.]+)/?$ page.php?theme=albums&pg=albums [L]
RewriteRule ^leaving-the-site/([^/\.]+)/?$ page.php?theme=leaving-the-site&pg=leaving-the-site&q=$1 [L]
RewriteRule ^([^/\.]+)/?/([^/\.]+)/?$ page.php?theme=$1&pg=$2 [L]
RewriteRule ^([^/\.]+)/?$ page.php?theme=$1&pg=$1 [L]
Everything seems fine, but as we're relaunching the site, we have approximately 110 301 redirects we need to put in place. These are similarly formatted to the following, and added after the above rewrite rules:
RewriteRule ^about/about-the-site$ https://www.mywebsite.com/about-us? [L,NC,R=301]
My problem is that as soon as I have the htaccess file uploaded with all the 301s, it starts to slow down the site, to the point of having 60 second load times within about 10 minutes and then starts timing out.
I remove the 301 redirects, and it recovers. From my research, 301 redirects can slow down a server, but 'not significantly', at least not with less than 1000 lines.
Is there something I should be doing differently?
This is combined HTTPS/SSL & www to non-www Rewrite|Redirect htaccess code specifically for WordPress, but you can modify/customize it for your particular site. I am still looking at your other code...
Edit: Ok I looked at your other code and it is overly complex and the use of question marks in your code may be incorrect. What I recommend you do is use RewriteCond Query String matching code instead of the direction/code you are trying to use now. See this topic for example RewriteCond Query String matching htaccess code examples: Replace "index.php?option=com_k2&view=item&id=" using .htaccess and Regex
# WP REWRITE LOOP START
# Rewrite|Redirect http to https|SSL & www to non-www
RewriteEngine On
RewriteBase /
RewriteCond %{HTTPS} !=on
RewriteCond %{SERVER_PORT} ^80
RewriteCond %{HTTP_HOST} ^www\.domainname\.com$ [NC]
RewriteRule (.*) https://%{HTTP_HOST}%{REQUEST_URI} [R,L]
RewriteRule ^index\.php$ - [L]
# All lines of Rewrite|Redirect code would go here
# if file or directory does not exist then Rewrite to index.php
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
# WP REWRITE LOOP END
I am not a new developer and have worked with .htaccess for years, but today I'm totally stuck and have no idea what is going on. Below is my full htaccess file:
Options All -Indexes
ReWriteEngine On
RewriteRule ^page/([a-zA-Z0-9_-]+)$ page.php?pageurl=$1
RewriteRule ^([a-zA-Z0-9_-]+)$ category.php?categoryurl=$1
RewriteRule ^([a-zA-Z0-9_-]+)/([a-zA-Z0-9_-]+)/([0-9]+)-([a-zA-Z0-9_-]+)$ product.php?category=$1&subcategory=$2&productid=$3&producturl=$4
RewriteCond %{HTTP_HOST} www.website\.com$ [NC]
RewriteRule ^(.*)$ http://website.com/$1 [R=301,L]
website.com/category should take me to the category page which it does, but for some reason the url gets changed, as if htaccess is working in reverse, I get sent to website.com/category.php?categoryurl=category.
This is exactly the same for the other ones, my product page should be website.com/category/subcategory/123-producturl but it redirects too:
website.com/product.php/category/123-producturl?category=category&subcategory=subcategory&productid=123&producturl=producturl
Anybody have any idea at all why this is doing what it is?
Try this one, you have not added flags to end the line in HTACCESS.
Options All -Indexes
ReWriteEngine On
RewriteRule ^page/([a-zA-Z0-9_-]+)$ page.php?pageurl=$1 [L]
RewriteRule ^([a-zA-Z0-9_-]+)$ category.php?categoryurl=$1 [L]
RewriteRule ^([a-zA-Z0-9_-]+)/([a-zA-Z0-9_-]+)/([0-9]+)-([a-zA-Z0-9_-]+)$ product.php?category=$1&subcategory=$2&productid=$3&producturl=$4 [L]
RewriteCond %{HTTP_HOST} www.website\.com$ [NC]
RewriteRule ^(.*)$ http://website.com/$1 [R=301,L]