I am trying to implement 301's for sub-pages on my site which is hosted on an Apache server (Fasthosts), using Rewrite scripts in the .htaccess file. I have tried to follow many pieces of documentation (infact, I've never had any problems implementing 301's using .htaccess before!) but on this particular website, nothing seems to work.
There is currently a 301 re-direct in there from non-www to www which is working fine. There are also some other snippets using regex which I imagine are for the CMS.
Below is the current state of the .htaccess file. An example of a 301 I'm trying to re-direct is in there (Lines 5 & 6)
Old page: http://www.junkwize.com/home-Garden%20Clearance
to New page: http://www.junkwize.com/services/garden-clearance-london
.htaccess file:
RewriteEngine On
RewriteCond %{HTTP_HOST} ^junkwize.com
RewriteRule (.*) http://www.junkwize.com/$1 [R=301]
RewriteCond %{HTTP_HOST} www.junkwize.com/home-Garden%20Clearance
RewriteRule (.*) http://www.junkwize.com/services/garden-clearance-london [R=301]
#Options +FollowSymlinks
RewriteRule ^.htaccess$ — [F]
RewriteRule ^([/admin]+)$ admin/login.php [L]
RewriteRule ^([/admin]+)([/blocks]+)$ admin/login.php [L]
RewriteRule ^([/blocks]+)$ index.php [L]
# RewriteRule ^([^/\.]+)-([^/\.]+)-([^/\.]+)$ index.php?main=$1&id=$2&menu=$3 [L]
RewriteRule ^([/deals]+)-([^/\.]+)$ index.php?main=$1&id=$2 [L]
# RewriteRule ^([^/\.]+)-([^/\.]+)$ index.php?main=$1&leftmain=$2 [L]
RewriteRule ^([^/\.]+)/([^/\.]+)$ index.php?main=$1&leftmain=$2 [L]
RewriteRule ^([^/\.]+)$ index.php?main=$1 [L]
Any help would be much appreciated.
Many thanks.
This code is faulty and is not going to work:
RewriteCond %{HTTP_HOST} www.junkwize.com/home-Garden%20Clearance
RewriteRule (.*) http://www.junkwize.com/services/garden-clearance-london [R=301]
Reason is that RewriteCond %{HTTP_HOST} can only match host name. Replace that code with this:
RewriteRule ^home-Garden\ Clearance/?$ /services/garden-clearance-london [R=301,L,NC]
Related
I'm rewriting a website with a larger google cache.
So my Problem is that the old links should be reachable but under a new URL.
I'm sitting since 8h to rewrite the URLs with htaccess... But it seems to be to hard for me, so how can I make this:
old htaccess:
RewriteEngine On
RewriteCond %{HTTP_HOST} ^www\.example\.com$ [NC]
RewriteRule ^(.*) https://example.com%{REQUEST_URI} [L,R=301]
RewriteRule ^banana/(.*).htm$ https://example.com/banana/index.php?id=$1 [R=301,L]
Future config wish:
1. https://example.com/banana/Berlin.htm
2. https://example.com/banana/index.php?id=Berlin
both leading to --> https://example.com/banana.php?id=Berlin
working .htaccess for rewrite 1:
RewriteCond %{REQUEST_URI} ^/banana [NC]
RewriteRule /(.*) https://example.com/banana.php?id=$1 [R=301,L]
working .htaccess for rewrite 2:
RewriteRule ^(.*) https://example.com%{REQUEST_URI} [L,R=301]
RewriteRule ^banana/(.*).htm$ https://example.com/banana.php?id=$1 [R=301,L]
But either I run into Too many redirects or to not working rewrites...
And when i got one config working fine the oder old URL is pointing to 404 ...
Thank you in advance and very much!
I know this is probably a very simple question but I do not manage it to get it working.
I have a joomla application with the following url: http://www.nmo-online.com/news/final and I would like to point it to http://www.nmo-online.com/client/frontend/app/final but with keeping the first url.
So I put a .htaccess file on my server situated in the root folder with the following content:
Options -Indexes
RewriteEngine On
RewriteBase /
RewriteCond %{HTTP_HOST} .*nmo-online.com$
RewriteRule ^news/final client/frontend/app/final [L]
The redirection seems to work but I always get redirected to the homepage, which is http://www.nmo-online.com/weather.
Any help is very appreciated.
enne
Edit: Here is the complete htaccess-file
Options -Indexes
RewriteEngine On
RewriteBase /
RewriteCond %{HTTP_HOST} .*nmo-online.com$
RewriteRule ^$ client/frontend/questionnaire/index.php [L]
RewriteRule ^weather client/frontend/app/weather [L]
RewriteRule ^news/final client/frontend/app/final [L]
RewriteRule ^flight/search-flight client/frontend/app/search-flight [L]
#Joomla backend
RewriteRule ^administrator client/frontend/app/administrator/ [L]
#Questionnaire backend
RewriteRule ^backend client/backend/index.php [L]
I have several urls on a Joomla site which have been indexed and I need to 301 redirect them into some new pages. The old URL is formed like this:
http://www.mydomain.com/en/wfmenuconfig/family/family-disease/177-category-english?start=20
I want it to go to:
http://www.mydomain.com/en/family-members/family-disease
I tried using:
RewriteCond %{QUERY_STRING} ^start=(.*)$
RewriteRule ^/en/wfmenuconfig/family/family-disease/177-category-english$ http://www.www.mydoamin.com/en/family-members/family-disease%1 [R=301,L]
I've tried several answers on here but nothing seems to be working.
htaccess 301 redirect dynamic url
and
301 Redirecting URLs based on GET variables in .htaccess
Any ideas what I should try next? (I've tried a normal redirect 301)
You've almost got it. You need to remove the leading slash from your rule's pattern because it's removed from the URI when applying rules from an htaccess file:
RewriteCond %{QUERY_STRING} ^start=(.*)$
RewriteRule ^en/wfmenuconfig/family/family-disease/177-category-english$ /en/family-members/family-disease%1? [R=301,L]
You also don't need the http://www.www.mydoamin.com bit (2 sets of www). At the end of your target, you have family-disease%1, which means if start=20 then the end of your URL will look like: family-disease20. Is that right?
The new URL doesn't have the query string in it, so it is just stripping of the last URL path part. If you want it hardcoded
RewriteCond %{QUERY_STRING} ^start=
RewriteRule ^en/wfmenuconfig/family/family-disease/177-category-english$ /en/family-members/family-disease? [R,L]
or a little bit more flexible
RewriteCond %{QUERY_STRING} ^start=
RewriteRule ^en/wfmenuconfig/family/family-disease/.+$ /en/family-members/family-disease? [R,L]
or if you just want to keep two levels after en/wfmenuconfig
RewriteCond %{QUERY_STRING} ^start=
RewriteRule ^en/wfmenuconfig/(.+?/.+?)/ /en/$1? [R,L]
Never test with 301 enabled, see this answer Tips for debugging .htaccess rewrite rules for details.
If you just want to redirect http://www.mydomain.com/en/wfmenuconfig/family/family-disease/177-category-english?start=$var into http://www.mydomain.com/en/family-members/family-disease, then you must try these directives:
# once per .htaccess file
Options +FollowSymlinks
RewriteEngine on
RewriteCond %{QUERY_STRING} start=([0-9]*)
RewriteRule ^en/wfmenuconfig/family/family-disease/177-category-english /en/family-members/family-disease [R=301,L]
But if that's not what you want, but to redirect http://www.mydomain.com/en/wfmenuconfig/family/family-disease/177-category-english?start=$var into http://www.mydomain.com/en/family-members/family-disease$var then you could check this one:
# once per .htaccess file
Options +FollowSymlinks
RewriteEngine on
RewriteCond %{QUERY_STRING} start=([0-9]*)
RewriteRule ^en/wfmenuconfig/family/family-disease/177-category-english /en/family-members/family-disease%1 [R=301,L]
Now, give this one a little more try if it will work. If it's not, then find any suspicious why this code is not working:
Options +FollowSymlinks
RewriteEngine on
RewriteBase /en/
RewriteCond %{QUERY_STRING} start=([0-9]*)
RewriteRule ^wfmenuconfig/family/family-disease/177-category-english /family-members/family-disease [R]
And go to http://www.mydomain.com/en/wfmenuconfig/family/family-disease/177-category-english?start=$AnyNumber if it's redirecting into http://www.mydomain.com/en/family-members/family-disease just make sure that your web server have mod_rewrite.
I just wanted to throw this out there, I was also having trouble getting the RewriteRule to work. I have a client that upgraded to a WordPress powered site from .asp pages. What I had to do to get this to work is insert the RewriteCond and RewriteRule in the htaccess file BEFORE the "# BEGIN WordPress" section. Now it works just as it should.
This is posted way late, but hopefully it helps someone else out there running into the same issue.
Doesn't Work:
# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>
# END WordPress
RewriteCond %{QUERY_STRING} ^var=somestring$ [NC]
RewriteRule ^oldpage\.asp$ http://www.domain.com/newpage? [R=301,L]
Does Work:
RewriteCond %{QUERY_STRING} ^var=somestring$ [NC]
RewriteRule ^oldpage\.asp$ http://www.domain.com/newpage? [R=301,L]
# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>
# END WordPress
Order of operations must be important =)
My client has a godaddy Virtual Dedicated Server (yes I know it sucks).... It has WHM VPS Optimized running on it .
I am trying to remove the index.php from the urls but my server still displays 404 errors I have looked at every forum in the universe and cant get an htaccess file that works. Here is what expression engine tells you to put use...
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{REQUEST_URI} !^(/index\.php|/img|/js|/css|/robots\.txt|/favicon\.ico)
RewriteRule ^(.*)$ /index.php/$1 [L]
</IfModule>
I know diddly about Apache.. please help kind sirs...
Test if the htaccess is working:
# Redirect domain
RewriteCond %{HTTP_HOST} ^www.yourdomain.com$
RewriteRule ^/?$ "http\:\/\/google\.com" [R=301,L]
Or
# Remove the www from the URL
RewriteCond %{HTTP_HOST} ^www\.(.+)$ [NC]
RewriteRule ^(.*)$ http://%1/$1 [R=301,L]
Ensure you actually have content appearing when you enter /index.php :P
Once you know your htaccess is working try "$1" instead of "%{REQUEST_URI}":
RewriteEngine on
RewriteCond $1 !^(img|admin\.php|themes|robots\.txt|index\.php|sitemap\.xml|/favicon\.ico) [NC]
RewriteRule ^(.*)$ /index.php?/$1 [L]
Also try "/index.php?/$1" instead of "/index.php/$1"
Ensure you have set EE (Admin->General Configuration) so "Name of your site's index page" is blank.
Remember that once you do get EE to work without the index.php appearing, it can be used both ways (with and without), which is bad for SEO, so remove it like so (place before the above rewrite :)
# Redirect index.php Requests (prevent site showing index.php in browser address bar)
RewriteCond %{THE_REQUEST} ^GET.*index\.php [NC]
RewriteRule (.*?)index\.php/*(.*) /$1$2 [R=301,L]
I have a site (sports.com, let's say) and I'd like to set up mod_rewrite so that a visitor to "football.sports.com/america" is shown content from "sports.com/stuff/place.php?id=america". I'd still like visitors to the naked "sports.com" to see "stuff/index.php".
Sorry, I'm a real newb with this. I've tried and failed several times, heres what I have so far...
IndexIgnore *
Options -Indexes
RewriteEngine On
RewriteCond %{HTTP_HOST} football\.sports\.com [NC]
RewriteRule ^([^/.]+)$ stuff/place.php?id=$1 [L]
RewriteRule (.*) stuff/index.php?%{QUERY_STRING}
Any help would be massively appreciated.
You can do this like:
RewriteRule ^america$ america/ [NC]
RewriteRule ^america/$ stuff/place.php?id=america [NC,L]
Redirects football.sports.com/america[/] to football.sports.com/stuff/place.php?id=america. This is a static rule: it won't work with france for example.
If you need a generic way you need :
RewriteRule ^([^/.]+)$ $1/ [NC]
RewriteRule ^(.*)/$ stuff/place.php?id=$1 [NC,L]
To get naked site to be redirected, add:
RewriteRule ^$ stuff/index.php [L]
Redirects football.sports.com/ to football.sports.com/stuff/index.php
Eventually you can add the query string of necessary.