I stupidly did a 301 redirect on websiteA.com to websiteB.com. After removing it from the .htaccess file the redirect is still in operation. I tried from outside the local network and it is still redirecting. I have cleared my cache and tried a different browser.
Does anybody have any suggestions?
UPDATE:
If I add a 302 redirect to this .htaccess file the site honours it. When I remove it, the old 301 redirect still happens.
.htaccess file for websiteA.com:
# -- concrete5 urls start --
Options -Indexes
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/$1 [L]
</IfModule>
# -- concrete5 urls end --
#RewriteCond %{HTTP_HOST} ^.*$
#RewriteRule ^/?$ "http\:\/\/www\.websiteB\.co\.uk\/" [R=301,L]
Try to visit the website with Developers Console open (F12)
Make sure you check "Disable cache" under "Network" tab
This will bypass 301 redirect cache on browser-side.
The browser caches the 301 Moved Permanently, until told otherwise. It is default behavior: http://www.w3.org/Protocols/rfc2616/rfc2616-sec10.html#sec10.3.2.
To fix it in IE9:
Open IE9 and press Ctrl+Shift+P for private browsing
Navigate to the problem URL
Then go back to normal browsing and all should be fine again
Just delete the line about the Redirect.
And also everyone who has Google Chrome, do the following steps:
Press CTRL + SHIFT + DELETE from your keyboard.
Only check -> "Files and images stored in cache"
Select in "Elements stored in cache since: Past week"
That will clear all your cache and you'll be fine.
The permanent redirect cache is probably in the browser
and in most browsers it is tricky to remove it.
But first, try using a different browser to see if this is the case.
In case the problem is in the browser:
This happened to me before and cleaning the browser data for that website was not enough.
I also realized that there is a trick for each browser.
In Safari (for Mac), I needed to select "Reset Safari..." (No panic, with this option neither bookmarks neither extensions are deleted).
I cannot recall how I did it for Chrome but was less traumatic.
The lesson
When playing with redirects use [302] first.
After everything was tested ok, change the code to [301]
I know this is an old post but i spent some time on the Web and my server to find the answer.
If you created an .htaccess file with a permanent redirection, the server will copy this redirection in the following file : "/var/.htaccess".
You have to edit this file to remove the redirection before cleaning the cache of your browser.
It worked on my Debian Jessie.
Try giving Apache a restart
(on Ubuntu servers: service apache restart or /etc/init.d/apache2 restart)
Related
I've build a website, using Next.js and SSG - Static Site Generation.
I'm serving the website on an Apache server and, therefore, because of this answer, I'm using the following .htaccess configuration:
# Disable directory indexes and MultiViews
Options -Indexes -MultiViews
# Prevent mod_dir appending a slash to directory requests
DirectorySlash Off
# Rewrite /foo to /foo.html if it exists
RewriteCond %{DOCUMENT_ROOT}%{REQUEST_URI}.html -f
RewriteRule !\.\w{2,4}$ %{REQUEST_URI}.html [L]
# Otherwise, rewrite /foo to /foo/index.html if it exists
RewriteCond %{DOCUMENT_ROOT}%{REQUEST_URI}/index.html -f
RewriteRule !\.\w{2,4}$ %{REQUEST_URI}/index.html [L]
# Handling 404
ErrorDocument 404 /my-custom-404.html
And it's been working perfectly.
But recently, there was a need for an admin page, the usual CRUD. I've developed it without SSG in mind (because there were actually no need for it), created my own custom router and used Next.js's catch all routes to handle all content of this admin page, which I called dashboard.
So, on my built website, I have a whole bunch of page.html files, and a /dashboard/[[...dashboard]].html file, which is the CRUD itself (all subpages and contents are imported dynamically) - and, therefore, every single link starting with /dashboard will be handled via that file.
So, the problem is: navigating through the links on the website and into the dashboard, everything works perfectly. But if I try to directly access any link within /dashboard (including itself, and subroutes: /dashboard/users, for instance), it simply does not work. With the provided .htaccess configuration, it goes straight to 404.
I've tried a few different configurations added to .htaccess, but none have worked so far (either it still goes straight to 404, or the browser shows the error ERR_TOO_MANY_REDIRECTS):
RewriteCond %{DOCUMENT_ROOT}/dashboard/$1
RewriteRule (.*) /dashboard/[[...dashboard]].html [L]
This one almost worked... but the dashboard itself does not do anything (no subpages are ever rendered):
RewriteCond %{REQUEST_URI} .*dashboard*.
RewriteRule (.*) /dashboard/[[...dashboard]].html [L]
Important note: this whole thing works perfectly on the local dev server.
If anyone has any tip on how I can sort this thing out, I would really appreciate it!
I've managed to solve it, at least on an acceptable level.
As I mentioned on the question, this was almost working (no sub page was ever rendered, but at least the browser was correctly redirecting to the dashboard):
RewriteCond %{REQUEST_URI} .*dashboard*.
RewriteRule (.*) /dashboard/[[...dashboard]].html [L]
No page was ever rendered, because I was using Next.js's withRouter/useRouter to inform my custom router of the current route (via router.asPath), and when the above rule as met, router.asPath was set to dashboard/[[...dashboard]].html.
So, I wrote a small test to redirect any access with that asPath to my entrypoint. Basically:
if(router.asPath.contains('[[...dashboard]]')
router.push('/dashboard')
But, another problem arouse...
The first problem was solved: trying to access any dashboard routes directly was working, but navigating through the website (links) was not. After an arduous and long process of trial and error, I found out that my previous .htaccess rule was preventing my client-side code to request my [[...dashboard]].html file.
RewriteCond %{REQUEST_URI} .*dashboard*.
RewriteCond %{REQUEST_URI} !(\[\[\.\.\.dashboard\]\])
RewriteRule (.*) /dashboard/[[...dashboard]].html?p=$1 [L]
Basically:
If my request URI contains 'dashboard'
AND if that same request does not contain [[...dashboard]]
THEN I rewrite it to the dashboard file
Hope this might help someone someday!
I'm new at programming. We have an office project, the website's URL is www.project.com.ph (sample name), this is already a live website from the client. But the released printouts have the instructions for the users to go to www.project.com/ph which is wrong and we can't reprint the material since it already reached plenty of event places.
Now the problem is, we need to redirect to www.project.com.ph automatically if the users type in the browser's address bar www.project.com/ph. I ask if this is possible without any kind of CMS or Wordpress and how to actually do it? We bought a new domain www.project.com for this. Any kind of help is appreciated.
Try the following near the top of your .htaccess file in the root of www.project.com. This works OK (although marginally less efficient) if both domains are pointing to the same place, since it specifically checks that we are requesting the "wrong" domain:
RewriteEngine On
RewriteCond %{HTTP_HOST} ^(www\.)?project\.com$ [NC]
RewriteRule ^ph/?(.*) http://www.project.com.ph/$1 [NC,R=302,L]
This will redirect requests for www.project.com/ph (no slash), www.project.com/ph/ (with a trailing slash) and www.project.com/ph/<whatever> to http://www.project.com.ph/<whatever>.
This is a temporary (302) redirect. Change it to a permanent (301) only when you are sure it's working OK.
From kj.'s answer on a similar question, here
In your .htaccess for www.project.com, this should do the trick.
RewriteEngine on
RewriteRule ^(.*)$ http://www.project.com.ph/ [R=permanent,NC,L]
This will redirect any request to project.com to the domain http://www.project.com.ph/
To include the path after the /ph/` you can use this.
RewriteEngine on
# redirect including path after ph/ (e.g. project.com/ph/directory/file.php to project.com.ph/directory/file.php
RewriteRule ^ph/(.*)$ http://www.project.com.ph/$1 [R=permanent,NC,L]
# redirect any other requests to project.com.ph index
RewriteRule ^(.*)$ http://www.project.com.ph/ [R=permanent,NC,L]
You can redirect (301 redirect) the URL using RewritrRule in .htaccess file
RewriteRule "http://www.project.com/ph/(.*)" "http://www.project.com.ph/$1" [L,NC,R=301]
I have made 301 redirect to redirect http://domain.com to http://www.domain.com with .htaccess,
I have done it this way.
Options +FollowSymlinks
RewriteEngine on
<IfModule mod_rewrite.c>
Rewritecond %{http_host} ^domain.com [nc]
Rewriterule ^(.*)$ http://www.domain.com/$1 [r=301,nc]
</IfModule>
I have written this code months ago it was working fine till now, but now all of a sudden it is showing two url's in browser history while redirecting properly,
1st url is http://domain.com
2nd url is http://www.domain.com
I removed the line Options +FollowSymlinks, but it still shows two url's.
Please suggest why I am getting two url's in browser history when I should be getting just redirected url.
Thanks
You are getting 2 URLs in your browser history now probably because you've upgraded your browser, changed browser settings, or are using a different browser . The FollowSymlinks option doesn't have anything to do with the browser's history. It's to tell the webserver that it is ok to follow symlinks in the directory that the option is turned on in.
The reason why you see both URLs in your browser history is because you are going to both URLs.
When you go to http://domain.com, your browser sends a resolves the domain.com host, then sends a request to that host. The response it gets back is essentially "what you are looking for is not here, go to http://www.domain.com instead, and continue to go there the next time you are looking for http://domain.com". The browser then processes the request for http://www.domain.com, by resolving the www.domain.com host, then sending a request to that host.
Thus, you've got a browsing history for http://domain.com, then http://www.domain.com.
I'm developing a plugin with the latest version of WordPress (3.4.2) locally (XAMPP 1.7.7 [PHP: 5.3.8]) and for some reason the links are not working within the plugin. I just have a simple delete link that links to a 'delete-gallery.php' file from within the plugin admin page. This file (delete-gallery.php) only calls a function to delete the record from the database and redirects back to the page that called it (the plugin admin page). Simple enough. But, when the link is clicked I get directed to XAMPP root (localhost:8080/xampp) and not the requested destination (delete-gallery.php) for some reason.
$url = plugins_url('includes/delete-gallery.php', _FILE_);
echo 'Delete';
I know the hrefs' path is correct on the link because it shows up in the status bar on hover, but for some reason it's not locating the file locally on submission. If I set the destination to somewhere external (ie. google.com, etc) it works fine, but not locally within wordpress.
The permalink structure has been updated and the .htaccess file is currently as so:
# 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
If I use a blank .htaccess file I don't get redirected to the XAMPP root, but instead get the error 'Object not found! The requested URL was not found on this server. ...' when the link is clicked.
Is there something that needs to be set in .htaccess to allow redirecting locally within wordpress? I'm at a loss here. Any suggestions would be greatly appreciated.
It was a simple sytax error. Had single underscores instead of doubles in the FILE parameter.
_FILE_ -> __FILE__
I want to redirect http://myip/admin to https://myip/admin. I am trying to use .htaccess to do this (want this only for the admin folder).
Contents of .htaccess placed in the relevant folder:
RewriteEngine On
RewriteCond %{HTTPS} !on
RewriteRule (.*) https://%{HTTP_HOST}%{REQUEST_URI}
(apache mod_rewrite is enabled). Both http://myip/admin and https://myip/admin are visible (but the redirection does not work). Server is Ubuntu.
I have tried few variations of the above rules from the internet but no luck :(
Any inputs would be appreciated.
regards,
JP
Solved it and learnt something new. The AllowOverride option in apache's main config file was not set correctly.
Also, if someone faces such issues 2 points:
1) apache reload may sometime not work as expected. Try restart
2) Clear browser cache and / or refresh page.