I am new to codeigniter. In fact, I'm not even working on it. I'm just employed to work the SEO for a website. I only have access to the cpanel of the site, not the dashboard of the codeigniter (I wonder if there is one?)
So far I have been able to figure out everything that needs my attention. Only problem now is the search bots seems to be hitting redirects. When I tried to fetch as Bingbot, I get the following
HTTP/1.1 301 Moved Permanently
Connection: close
Date: Sun, 12 Jun 2016 00:34:29 GMT
Content-Length: 234
Content-Type: text/html; charset=iso-8859-1
Location: http://www.domain.com/
Server: Apache
<!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML 2.0//EN">
<html><head>
<title>301 Moved Permanently</title>
</head><body>
<h1>Moved Permanently</h1>
<p>The document has moved here.</p>
</body></html>
I figured it might be the redirect rules written into the .htaccess. But I really don't know what to change to allow for the bot to smoothly crawl the site. View .htaccess below.
<IfModule mod_rewrite.c>
<IfModule mod_negotiation.c>
Options -MultiViews
</IfModule>
RewriteEngine On
RewriteCond %{HTTP_HOST} !^www\.
RewriteRule ^(.*)$ http://www.%{HTTP_HOST}/$1 [R=301,L]
# Redirect Trailing Slashes...
RewriteRule ^(.*)/$ /$1 [L,R=301]
# Handle Front Controller...
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ index.php [L]
</IfModule>
What do I need to add to the .htaccess file to allow search engines crawl the site without hitting to http 301 again? Thanks
Why did you put this code in .htaccess file?
# Redirect Trailing Slashes...
RewriteRule ^(.*)/$ /$1 [L,R=301]
Related
I want to use 301 redirects for my website URLs. The URL redirects to the wrong path and the website give me a 404 error. When I use this redirect.
Redirect 301 /couponstore/evitamins-120 https://website.com/codes/evitamins-coupon-codes
it gives me a result like this
https://website.com/codes/evitamins-coupon-codes?lcp=couponstore/evitamins-120
the lcp=couponstore/evitamins-120 is an extra part and it is injected to the URL due to the .htaccess rewrite. When I remove the last part of the rewrite rule ^((.*?)(\-(\d+))?)([.]\w+)?$ index.php?lcp=$1&lcp_id=$4&ext=$5 [QSA,L] then my website stop working and I am getting errors on all pages.
Below is the .htaccess code for my website:
<IfModule mod_rewrite.c>
## Turn on rewrite engine
RewriteEngine on
## Coupons CMS v7
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^((.*?)(\-(\d+))?)([.]\w+)?$ index.php?lcp=$1&lcp_id=$4&ext=$5 [QSA,L]
</IfModule>
what should I do to use redirects for my website URLs, I lost all the SEO for my website due to this one issue which I am not capable to resolve, need suggestion/help to redirect old URLs to the new.
thank you.
Based on your shown samples, could you please try following. Please make sure to clear your browser cache before testing your URLs.
<IfModule mod_rewrite.c>
## Turn on rewrite engine
RewriteEngine ON
## Coupons CMS v7
RewriteRule ^(couponstore/evitamins-120)/?$ codes/evitamins-coupon-codes [R=301,NC,L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^((.*?)(\-(\d+))?)([.]\w+)?$ index.php?lcp=$1&lcp_id=$4&ext=$5 [QSA,L]
</IfModule>
My htaccess is getting stuck in an infinite loop. I'm trying to strip the .html extension off a URL, if there is one, and then use the leftover string as a query string.
RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /.*\.html\ HTTP/
RewriteRule ^(.*)\.html$ /$1 [R=302,L]
RewriteRule ^resources/blog$ /resources/blog/ [R=302,L,QSA]
RewriteRule ^resources/blog/$ resources/blog.php [L,QSA]
RewriteRule ^resources/blog/.*?([^\.\/]*)$ resources/blog.php?pname=$1 [L,QSA]
UPDATE:
Here's how it sit at this time. I've commented some stuff out while troubleshooting.
Options +SymLinksIfOwnerMatch -MultiViews
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
#Redirect to URL without .html extension (Pretty URL)
RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /.*\.html\ HTTP/
RewriteRule ^(.*)\.html$ /$1 [R=302]
# Pretty url for Couch CMS blog
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^resources/blog/.*?([^\.\/]*)$ resources/blog.php?pname=$1 [L,QSA,END]
RewriteRule ^resources/blog$ /resources/blog/ [R=302,L,QSA]
RewriteRule ^resources/blog/$ resources/blog.php [L,QSA]
# RewriteRule ^resources/blog/([1-2]\d{3})/(?:(0[1-9]|1[0-2])/(?:(0[1-9]|1[0-9]|2[0-9]|3[0-1])/)?)?$ resources/blog.php?d=$1$2$3 [L,QSA]
# RewriteRule ^resources/blog/[^\.]*?([^/\.]*)/$ resources/blog.php?fname=$1 [L,QSA]
# RewriteRule ^resources/blog/[^\.]*?([^/\.]*)$ "$0/" [R=302,L,QSA]
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}.html -f
RewriteRule ^(.+)$ $1.html [L,QSA]
</IfModule>
UPDATE 2
File structure is as follow:
/
|-- static_html_files/
|-- resources/
|----- blog.php
|----- newsletter.html
|-- .htaccess
|-- index.html
Most files are static and their URL's need to be 'prettified' by stripping the .html extension from them and then redirected to with the pretty URL.
The blog.php has to be prettified as well and the Couch CMS generated links need to be rewritten. The rule for rewriting the couch cms links is the one that keeps looping.
UPDATE 3
It seems there is a 301 redirect somewhere but I don't have a 301 in my htaccess? Not sure where to go from here or where to look for this redirect. See Redirect Check results below:
https://xxxxx.ca/resources/blog/yyyyy
HTTP/1.1 301 Moved Permanently
Date: Tue, 25 Jun 2019 20:58:31 GMT
Server: Apache
Expires: Thu, 19 Nov 1981 08:52:00 GMT
Cache-Control: no-store, no-cache, must-revalidate
Pragma: no-cache
Set-Cookie: PHPSESSID=poplcjkqcgd4gk57c1l3lcdjg7; path=/
Location: https://xxxxx.ca/resources/blog/yyyyy.html
Transfer-Encoding: chunked
Content-Type: text/html; charset=UTF-8
https://xxxxx.ca/resources/blog/yyyyy.html
HTTP/1.1 302 Found
Date: Tue, 25 Jun 2019 20:58:31 GMT
Server: Apache
Location: https://xxxxx.ca/resources/blog/yyyyy
Content-Length: 263
Content-Type: text/html; charset=iso-8859-1
[RINSE & REPEAT AD NAUSEAM]
UPDATE 4
After some debugging, I seem to be having an Apache problem with mod_rewrite and 'add path info postfix' which is generally solved by specifying -MultiViews and/or adding the DPI flag to the rules but neither of these seem to solve any of my problems.
I've inherited an old website which has been through a few different domain names and file types. It used to have .aspx pages. Then it switched to .php (which it still is today). My .htaccess file is sort of a mess. I could use some help cleaning it up to accomplish the following:
Here's the history:
Old domain: stuff.olddomain.info
New domain: www.newdomain.com
The twist: www.newdomain.com used to have .aspx pages which are still indexed by Google
Redirect all old domain traffic to the new domain
Redirect all traffic to www
Redirect all .aspx traffic to the home page -> www.newdomain.com
The redirects from .aspx also have some variables at the end (www.newdomain.com/index.aspx?thing=123). I need to strip all of that extra stuff and just redirect to www.newdomain.com
Hide .php from all urls (www.newdomain.com/page.php shows as www.newdomain.com/page)
I have everything working except for the .aspx redirects. What am I missing?
RewriteEngine On
RewriteBase /
# REDIRECT ASPX PAGES FROM PREVIOUS DOMAIN
RewriteCond %{REQUEST_FILENAME}\.aspx$ -f
RewriteRule www.newdomain.com [R=301,L]
### REDIRECT TO WWW FIRST
RewriteCond %{HTTP_HOST} ^[^.]+\.[^.]+$
RewriteRule ^(.*)$ http://www.%{HTTP_HOST}/$1 [L,R=301]
#RewriteCond %{HTTP_HOST} ^www\.(.*)$ [NC]
#RewriteRule ^(.*)$ http://%1/$1 [R=301,L]
# browser requests PHP
RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /([^\ ]+)\.php
RewriteRule ^/?(.*)\.php$ /$1 [L,R=301]
# check to see if the request is for a PHP file:
RewriteCond %{REQUEST_FILENAME}\.php -f
RewriteRule ^/?(.*)$ /$1.php [L]
# Cache Control - 52 Weeks
<FilesMatch "\.(ico|pdf|flv|jpg|jpeg|png|gif|js|css|swf)$">
Header set Cache-Control "max-age=3153600, public"
</FilesMatch>
I know that's probably a mess, so any help is appreciated.
I have an existing site with php in the URL indexed. I want to change the URLs to not include PHP so thepage.php will be rewritten to http://example.com/thepage
The rewrite is working, but the redirect causes a 'page can't be displayed in a loop' error when I try to access the page as using thepage.php
I need to figure out how to setup the redirect and also rewrite the URLs, because Google has now indexed the PHP URLs and the pretty URLs.
I've looked at countless pages online, but can't find the answer.
Please help.
Here's my htaccess
# The redirect below caused a loop when I access the page as
# http://example.com/thepage.php
# Moving the redirect after the rewrite didn't work either.
Redirect 301 /thepage.php http://example.com/thepage
RewriteEngine on
# Rewrite works. The page does display corectly for this link
# http://example.com/thepage
<IfModule mod_rewrite.c>
Options +FollowSymLinks
Options +Indexes
# RewriteEngine On
RewriteCond %{SCRIPT_FILENAME} !-d
#RewriteRule ^photos([^\.]+)$ photos [NC,L]
RewriteRule ^([^\.]+)$ $1.php [NC,L]
</IfModule>
ErrorDocument 404 http://example.com/
Thank You
Your rewrite rule is backward from the sounds of it.
Here we're capturing all php files that do no contain periods and redirecting them to a directory URI using only the name without the extension. [R=301] is a permanent 301 redirect that tells whoever that the page is no longer in its old place.
RewriteEngine on
RewriteRule ^([^\.]+).php$ $1 [NC,L,R=301]
You might want to test these with R only without the 301 to make sure it's working. If you do a 301 redirect that doesn't work it will be cached in the end user's browser cache until it expires.
Apache has an extensive reference on remapping URLs with redirects.
I finally was able to get back to this problem and found the solution. I hope this can help somebody else. I tore my hair out on this problem.
I found many examples but not with the combination that I needed
#Force non-www:
RewriteEngine on
RewriteCond %{HTTP_HOST} ^www.example.com [NC]
RewriteRule ^(.*)$ http://example.com/$1 [L,R=301,NC]
RewriteBase /
# hide .php extension
# To externally redirect /dir/foo.php to /dir/foo
RewriteCond %{THE_REQUEST} ^[A-Z]{3,}\s([^.]+).php [NC]
RewriteRule ^ %1 [R,L,NC]
# To internally redirect /dir/foo to /dir/foo.php
RewriteCond %{REQUEST_FILENAME}.php -f
RewriteRule ^ %{REQUEST_URI}.php [L]
ErrorDocument 404 http://example.com/
I am updating an old asp site to cakephp - the old site has various listings on google based on the old "filename.asp" urls - I'd like to put Redirect 301s in the htaccess file to try and hang on to those search results (most of the pages have a complementing page on the new site), but something appears to be going wrong. htaccess as follows (excluding standard cake stuff). What am I doing wrong?
Redirect 301 contact.asp /contact
Redirect 301 portfolio.asp /portfolio-design-web
Redirect 301 webhosting.asp /
I've tried with the htaccess in the root directory, and webroot but it should just work wherever, no?
--
fixed it using mod_rewrite, following rules inside .htaccess on webroot work:
RewriteRule ^contact.asp$ /contactos/ [R=301,L]
Try modifying app/webroot/.htaccess like so:
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteRule ^contact.asp$ /contact [R=301,L]
RewriteRule ^portfolio.asp$ /portfolio-design-web [R=301,L]
RewriteRule ^webhosting.asp$ / [R=301,L]
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)$ index.php?url=$1 [QSA,L]
</IfModule>