How to redirect my deleted links - apache

i have my site where in pas i have a article directory but now i have deleted that article directory and google webmaster is shoing those links as not found and its a negative impact on my search results.
pls help me to redirect all links like this
http://www.mydomain.com/article/arts-entertainment/bradley-spalter-songs-getting-past-emotionally-charged-barriers/
to
http://www.mydomain.com
Current .htaccess file:
## EXPIRES CACHING ##
<IfModule mod_expires.c>
ExpiresActive On
ExpiresByType image/jpg "access 1 month"
ExpiresByType image/jpeg "access 1 month"
ExpiresByType image/gif "access 1 month"
ExpiresByType image/png "access 1 month"
ExpiresByType text/css "access 1 month"
ExpiresByType text/html "access 1 day"
ExpiresByType text/plain "access 1 month"
ExpiresByType application/pdf "access 1 month"
ExpiresByType text/javascript "access 1 month"
ExpiresByType application/javascript "access 1 month"
ExpiresByType application/x-shockwave-flash "access 1 month"
ExpiresByType image/x-icon "access 1 month"
ExpiresDefault "access 15 days"
</IfModule>
## EXPIRES CACHING ##
Options -MultiViews -Indexes +FollowSymlinks
RewriteCond %{http_host} ^mydomain.com [NC]
RewriteRule ^(.*)$ http://www.mydomain.com/$1 [R=301,NC]
RewriteRule ^golmagico/(.*)$ en/index.php?title=$1 [PT,L,QSA]
<IfModule mod_security.c>
SecFilterEngine Off
SecFilterScanPOST Off
</IfModule>
ErrorDocument 401 /default_error.php
ErrorDocument 402 /default_error.php
ErrorDocument 403 /default_error.php
ErrorDocument 404 /default_error.php
<IfModule mod_php5.c>
php_value register_globals 0
php_value magic_quotes_gpc 0
php_value session.auto_start 0
php_value safe_mode 0
</IfModule>
<IfModule sapi_apache2.c>
php_value register_globals 0
php_value magic_quotes_gpc 0
php_value session.auto_start 0
php_value safe_mode 0
</IfModule>
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteRule ^detailed/recent/?([^/\.]+)?/?$ video.php?category=recent&page=$1&viewtype=detailed
RewriteRule ^detailed/viewed/?([^/\.]+)?/?$ video.php?category=viewed&page=$1&viewtype=detailed
RewriteRule ^detailed/recentviewed/?([^/\.]+)?/?$ video.php?category=recentviewed&page=$1&viewtype=detailed
RewriteRule ^detailed/discussed/?([^/\.]+)?/?$ video.php?category=discussed&page=$1&viewtype=detailed
RewriteRule ^detailed/favorites/?([^/\.]+)?/?$ video.php?category=favorites&page=$1&viewtype=detailed
RewriteRule ^detailed/rated/?([^/\.]+)?/?$ video.php?category=rated&page=$1&viewtype=detailed
RewriteRule ^detailed/featured/?([^/\.]+)?/?$ video.php?category=featured&page=$1&viewtype=detailed
RewriteRule ^detailed/random/?([^/\.]+)?/?$ video.php?category=random&page=$1&viewtype=detailed
RewriteRule ^recentviewed/?([^/\.]+)?/?$ video.php?category=recentviewed&page=$1
RewriteRule ^videos/?([^/\.]+)?/?$ video.php?category=recent&page=$1
RewriteRule ^recent/?([^/\.]+)?/?$ video.php?category=recent&page=$1
</IfModule>
<IfModule mod_deflate.c>
AddOutputFilterByType DEFLATE application/x-javascript text/css text/html text/xml
</IfModule>

Try putting this in your .htaccess
ErrorDocument 404 http://www.mydomain.com
it'll redirect all 404's to your domain.
or you can try:
RewriteRule ^articles/.*?$ / [NC]
to redirect all requests to the articles folder to root

Enable mod_rewrite
Enable .htacccess
Create a .htaccess file under DOCUMENT_ROOT
and place this code in there:
Options +FollowSymLinks -MultiViews
# Turn mod_rewrite on
RewriteEngine On
RewriteBase /
RewriteRule ^article/ / [NC,L,R=301]
R=301 will tell Google and other search bots that all the links starting with /article/ have permanently moved to / (home page) and you will not have any negative impact on your rankings.

Related

Apache server, two cache control max-age values

Im trying to set up cache control for a site running on Ubuntu 16.04 using an Apache server. This is the .htaccess file for the site:
## EXPIRES CACHING ##
<IfModule mod_expires.c>
ExpiresActive On
ExpiresByType image/jpg "access 1 year"
ExpiresByType image/jpeg "access 1 year"
ExpiresByType image/gif "access 1 year"
ExpiresByType image/png "access 1 year"
ExpiresByType text/css "access 1 month"
ExpiresByType application/pdf "access 1 month"
ExpiresByType application/javascript "access 1 month"
ExpiresByType application/x-javascript "access 1 month"
ExpiresByType application/x-shockwave-flash "access 1 month"
ExpiresByType image/x-icon "access 1 year"
ExpiresDefault "access 2 days"
</IfModule>
## EXPIRES CACHING ##
<IfModule mod_rewrite.c>
<IfModule mod_negotiation.c>
Options -MultiViews
</IfModule>
Options +FollowSymLinks
RewriteEngine On
# Redirect Trailing Slashes If Not A Folder...
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)/$ /$1 [L,R=301]
# Handle Front Controller...
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ index.php [L]
# Handle Authorization Header
RewriteCond %{HTTP:Authorization} .
RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}]
</IfModule>
When checking the headers in Chrome dev tools for an image, I see two max-age values:
Cache-Control:max-age=60, public, max-age=31536000
Content-Type:image/jpeg
It seems like the first value is overriding the second value because no resources on my site are being cached for more than a minute. Where is the first value of 60 being defined?

Apache Rewrite Rule on Dispatcher

How can I do a rewrite rule for both http://domain/abc to rewite/redirect to http://domain/abc.html but it should work when I have url as http://domain/abc/def.html. Currently when I do redirect 301 "abc" "abc.hml" the second url is also redirecting to http://domain/abc.html/def.html.
My current rules.
<IfModule rewrite_module>
RewriteEngine On
RewriteRule ^/$ /content/aaa-123/abc.html [PT,L]
RewriteRule ^/index.html$ /content/aaa-123/abc.html [PT,L]
RedirectMatch ^/abc$ /abc.html
RewriteCond %{REQUEST_URI} !^/(.*)/$
RewriteCond %{REQUEST_URI} !^(.*)\.(.*)$
RewriteRule ^/(.*)$ /content/$1/ [L]
RewriteRule \.(css|jpe?g|gif|png|js)$ - [L]
ErrorDocument 404 /errors/404.html
<IfModule mod_expires.c>
ExpiresActive on
ExpiresByType image/jpg "access 1 year"
ExpiresByType image/jpeg "access 1 year"
ExpiresByType image/gif "access 1 year"
ExpiresByType image/png "access 1 year"
ExpiresByType text/css "access 1 month"
ExpiresByType text/html "access 1 month"
ExpiresByType application/pdf "access 1 month"
ExpiresByType text/x-javascript "access 1 month"
ExpiresByType text/css "access plus 1 year"
ExpiresByType application/x-shockwave-flash "access 1 month"
ExpiresByType image/x-icon "access 1 year"
ExpiresDefault "access 1 month"
</IfModule>
<IfModule mod_headers.c>
<FilesMatch "\.(js|css|xml|gz)$">
Header append Vary: Accept-Encoding
</FilesMatch>
</IfModule>
Thanks
Use RedirectMatch instead of Redirect to match using regular expressions:
Options -MultiViews
RewriteEngine On
RewriteRule ^/abc/?$ /abc.html [NC,L,R=302]
RewriteRule \.(css|jpe?g|gif|png|js)$ - [L,NC]
RewriteRule ^/(index\.html)?$ /content/aaa-123/abc.html [PT,L,NC]
RewriteCond %{REQUEST_URI} !^/(.*)/$
RewriteCond %{REQUEST_URI} !^(.*)\.(.*)$
RewriteRule ^/(.*)$ /content/$1/ [L]
Clear your browser cache before testing this rule and do restart Apache after making these changes.
For the first you could use this:
RedirectMatch ^/abc$ /abc.html
This tells apache to redirect only "/abc"
Although it sounds as you want MULTIVIEWS in Apache. Multiviews is an Option with which Apache will examine a request and add an extension if it finds a file matching the request, so if you request abc and there is abc.html it will load it.

Leverage Browser Caching in site

I have developed my site using magento and anguar js. From google page Insights, I got that I have to leverage browser caching. So for that, I have defined my .htaccess file lke this:
RewriteEngine On
Options FollowSymLinks
RewriteBase /
RewriteCond %{HTTP_USER_AGENT} (facebookexternalhit/[0-9]|Twitterbot|Pinterest|Google.*snippet)
RewriteRule ^(.*)$ story.php?id=$1 [L,QSA]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{HTTP_USER_AGENT} !facebookexternalhit/[0-9]
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ /#/$1 [L]
<IfModule mod_headers.c>
# YEAR
<FilesMatch "\.(ico|gif|jpg|jpeg|png|flv|pdf)$">
Header set Cache-Control "max-age=29030400"
</FilesMatch>
# WEEK
<FilesMatch "\.(js|css|swf|woff)$">
Header set Cache-Control "max-age=604800"
</FilesMatch>
# 45 MIN
<FilesMatch "\.(html|htm|txt)$">
Header set Cache-Control "max-age=86400"
</FilesMatch>
Header set Connection keep-alive
</IfModule>
But this is not working as the google insight is still showing the same message.
You should use mod_expires to check which assets should be reloaded after a certain time. In your .htaccess file you can configure it like so:
<IfModule mod_expires.c>
ExpiresActive On
ExpiresDefault "access plus 2 days"
ExpiresByType image/gif "access plus 2592000 seconds"
ExpiresByType image/jpeg "access plus 2592000 seconds"
ExpiresByType image/png "access plus 2592000 seconds"
ExpiresByType text/javascript "access 1 month"
ExpiresByType text/x-javascript "access 1 month"
ExpiresByType application/javascript "access 1 month"
ExpiresByType application/x-javascript "access 1 month"
ExpiresByType application/json "access 1 month"
</IfModule>
As you can see there is an ExpiresDefault of 2years from access time on. For all images and javascripts you can spot the time. If you need other values you can find extensive docs here http://httpd.apache.org/docs/current/mod/mod_expires.html

RewriteRule / RewriteCond simply not working

Firstly I know there are a lot of similar questions on here and I can assure you that I have been looking through them. I've tried loads of variations using the answers here but after spending the entire morning trying to get this working I'm giving in and asking for help.
I've got the following Conditions and Rules in my .htaccess file but they simply aren't working:
# 301 --- http://www.example.com/ProjectSection.aspx?id=10 => http://example.com/projects/maintenance
RewriteCond %{HTTP_HOST} ^www\.example\.com$
RewriteCond %{QUERY_STRING} (^|&)id=10($|&)
RewriteRule ^ProjectSection\.aspx$ http://example.com/services/maintenance/? [L,R=302]
# 301 --- http://www.example.com/ProjectSection.aspx => http://example.com/projects
RewriteRule ^ProjectSection\.aspx$ http://example.com/projects? [L,R=302]
When I visit www.example.com/ProjectSection.aspx I get taken to a 404 page with the URL of http://example.com/ProjectSection.aspx. If anyone can help in the slightest I would be most grateful, I'm going bloody mad!!
Here is the full .htaccess file (it's a big en) and the code above is placed at the bottom.
# Enable Rewrite Engine
# ------------------------------
RewriteEngine On
RewriteBase /
# Redirect index.php Requests
# ------------------------------
RewriteCond %{THE_REQUEST} ^[^/]*/index\.php [NC]
RewriteCond %{THE_REQUEST} ^GET
RewriteRule ^index\.php(.+) $1 [R=301,L]
# Standard ExpressionEngine Rewrite
# ------------------------------
RewriteCond $1 !\.(css|js|gif|jpe?g|png) [NC]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ /index.php/$1 [L]
<IfModule mod_setenvif.c>
<IfModule mod_headers.c>
<FilesMatch "\.(gif|ico|jpe?g|png|svg|svgz|webp)$">
SetEnvIf Origin ":" IS_CORS
Header set Access-Control-Allow-Origin "*" env=IS_CORS
</FilesMatch>
</IfModule>
</IfModule>
<IfModule mod_headers.c>
<FilesMatch "\.(eot|font.css|otf|ttc|ttf|woff)$">
Header set Access-Control-Allow-Origin "*"
</FilesMatch>
</IfModule>
Options -MultiViews
<IfModule mod_headers.c>
Header set X-UA-Compatible "IE=edge"
<FilesMatch "\.(appcache|crx|css|eot|gif|htc|ico|jpe?g|js|m4a|m4v|manifest|mp4|oex|oga|ogg|ogv|otf|pdf|png|safariextz|svg|svgz|ttf|vcf|webapp|webm|webp|woff|xml|xpi)$">
Header unset X-UA-Compatible
</FilesMatch>
</IfModule>
<IfModule mod_mime.c>
# Audio
AddType audio/mp4 m4a f4a f4b
AddType audio/ogg oga ogg
# JavaScript
# Normalize to standard type (it's sniffed in IE anyways):
# http://tools.ietf.org/html/rfc4329#section-7.2
AddType application/javascript js jsonp
AddType application/json json
# Video
AddType video/mp4 mp4 m4v f4v f4p
AddType video/ogg ogv
AddType video/webm webm
AddType video/x-flv flv
# Web fonts
AddType application/font-woff woff
AddType application/vnd.ms-fontobject eot
# Browsers usually ignore the font MIME types and sniff the content,
# however, Chrome shows a warning if other MIME types are used for the
# following fonts.
AddType application/x-font-ttf ttc ttf
AddType font/opentype otf
# Make SVGZ fonts work on iPad:
# https://twitter.com/FontSquirrel/status/14855840545
AddType image/svg+xml svg svgz
AddEncoding gzip svgz
# Other
AddType application/octet-stream safariextz
AddType application/x-chrome-extension crx
AddType application/x-opera-extension oex
AddType application/x-shockwave-flash swf
AddType application/x-web-app-manifest+json webapp
AddType application/x-xpinstall xpi
AddType application/xml atom rdf rss xml
AddType image/webp webp
AddType image/x-icon ico
AddType text/cache-manifest appcache manifest
AddType text/vtt vtt
AddType text/x-component htc
AddType text/x-vcard vcf
</IfModule>
AddDefaultCharset utf-8
<IfModule mod_mime.c>
AddCharset utf-8 .atom .css .js .json .rss .vtt .webapp .xml
</IfModule>
<IfModule mod_rewrite.c>
Options +FollowSymlinks
# Options +SymLinksIfOwnerMatch
RewriteEngine On
# RewriteBase /
</IfModule>
<IfModule mod_rewrite.c>
RewriteCond %{HTTPS} !=on
RewriteCond %{HTTP_HOST} ^www\.(.+)$ [NC]
RewriteRule ^ http://%1%{REQUEST_URI} [R=301,L]
</IfModule>
<IfModule mod_autoindex.c>
Options -Indexes
</IfModule>
<IfModule mod_rewrite.c>
RewriteCond %{SCRIPT_FILENAME} -d [OR]
RewriteCond %{SCRIPT_FILENAME} -f
RewriteRule "(^|/)\." - [F]
</IfModule>
<FilesMatch "(^#.*#|\.(bak|config|dist|fla|inc|ini|log|psd|sh|sql|sw[op])|~)$">
Order allow,deny
Deny from all
Satisfy All
</FilesMatch>
<IfModule mod_deflate.c>
<IfModule mod_setenvif.c>
<IfModule mod_headers.c>
SetEnvIfNoCase ^(Accept-EncodXng|X-cept-Encoding|X{15}|~{15}|-{15})$ ^((gzip|deflate)\s*,?\s*)+|[X~-]{4,13}$ HAVE_Accept-Encoding
RequestHeader append Accept-Encoding "gzip,deflate" env=HAVE_Accept-Encoding
</IfModule>
</IfModule>
<IfModule mod_filter.c>
AddOutputFilterByType DEFLATE application/atom+xml \
application/javascript \
application/json \
application/rss+xml \
application/vnd.ms-fontobject \
application/x-font-ttf \
application/x-web-app-manifest+json \
application/xhtml+xml \
application/xml \
font/opentype \
image/svg+xml \
image/x-icon \
text/css \
text/html \
text/plain \
text/x-component \
text/xml
</IfModule>
</IfModule>
<IfModule mod_headers.c>
Header unset ETag
</IfModule>
FileETag None
<IfModule mod_expires.c>
ExpiresActive on
ExpiresDefault "access plus 1 month"
# CSS
ExpiresByType text/css "access plus 1 year"
# Data interchange
ExpiresByType application/json "access plus 0 seconds"
ExpiresByType application/xml "access plus 0 seconds"
ExpiresByType text/xml "access plus 0 seconds"
# Favicon (cannot be renamed!)
ExpiresByType image/x-icon "access plus 1 week"
# HTML components (HTCs)
ExpiresByType text/x-component "access plus 1 month"
# HTML
ExpiresByType text/html "access plus 0 seconds"
# JavaScript
ExpiresByType application/javascript "access plus 1 year"
# Manifest files
ExpiresByType application/x-web-app-manifest+json "access plus 0 seconds"
ExpiresByType text/cache-manifest "access plus 0 seconds"
# Media
ExpiresByType audio/ogg "access plus 1 month"
ExpiresByType image/gif "access plus 1 month"
ExpiresByType image/jpeg "access plus 1 month"
ExpiresByType image/png "access plus 1 month"
ExpiresByType video/mp4 "access plus 1 month"
ExpiresByType video/ogg "access plus 1 month"
ExpiresByType video/webm "access plus 1 month"
# Web feeds
ExpiresByType application/atom+xml "access plus 1 hour"
ExpiresByType application/rss+xml "access plus 1 hour"
# Web fonts
ExpiresByType application/font-woff "access plus 1 month"
ExpiresByType application/vnd.ms-fontobject "access plus 1 month"
ExpiresByType application/x-font-ttf "access plus 1 month"
ExpiresByType font/opentype "access plus 1 month"
ExpiresByType image/svg+xml "access plus 1 month"
</IfModule>
Options +FollowSymLinks
RewriteEngine On
I've stripped out a lot of comments and the other 301 rewrites however they all follow the same pattern, just with a different ID.
Any help would be amazing.
Thank you.
I've managed to fix this, although I'm still not sure if this is the correct way to do so but here is the code regardless:
# 301 --- http://www.example.com/ProjectSection.aspx?id=10 => http://example.com/projects/maintenance
RewriteCond %{QUERY_STRING} (^|&)id=10($|&)
RewriteRule ^(.*)/ProjectSection\.aspx$ http://example.com/services/maintenance/? [L,R=302]
# 301 --- http://www.example.com/ProjectSection.aspx => http://example.com/projects
RewriteRule ^(.*)/ProjectSection\.aspx http://example.com/projects? [L,R=302]
I've added, what I call, a catch all sign (is this what it is called?) in front of the ProjectSection part of the URL and this appears to have corrected it all.

url rewriting script not working

In a nutshell the script im using is not working
the script
RewriteEngine On
RewriteRule ^([a-zA-Z0-9_-]+)$ profiles.php?key=$1
RewriteRule ^([a-zA-Z0-9_-]+)/$ profiles.php?key=$1
the original url :
http://localhost/profiles?profile_key=yasin%20allana
the desired url:http://localhost/profiles/yasin%20allana
the error:The server encountered an internal error or misconfiguration and was unable to complete your request.
how do i correct the errors
note:the server is v 1.8.3 xampp
the complete htaccess script
<IfModule mod_deflate.c>
<FilesMatch "\.(html|txt|css|js|php|pl)$">
SetOutputFilter DEFLATE
</FilesMatch>
</IfModule>
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}\.php -f
RewriteRule ^(.*)$ $1.php
# BEGIN Expires
<ifModule mod_expires.c>
ExpiresActive On
ExpiresDefault "access plus 1 seconds"
ExpiresByType text/html "access plus 1 seconds"
ExpiresByType image/gif "access plus 2592000 seconds"
ExpiresByType image/jpeg "access plus 2592000 seconds"
ExpiresByType image/png "access plus 2592000 seconds"
ExpiresByType text/css "access plus 604800 seconds"
ExpiresByType text/javascript "access plus 216000 seconds"
ExpiresByType application/x-javascript "access plus 216000 seconds"
</ifModule>
# END Expires
#override the limit on upload in php
php_value upload_max_filesize 10M
php_value post_max_size 10M
php_value max_input_time 300
php_value max_execution_time 300
You can use this rule in /profiles/.htaccess file:
RewriteEngine On
RewriteBase /profiles/
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^([^/.]+)/?$ profiles.php?key=$1 [L,QSA]