About:
Site in kohana, version 3.0.8.
Problem:
I want to close for search engines whole site, except
baseinvest.kz/project and inner pages of it(baseinvest.kz/project/view/110)
.htaccess file
RewriteEngine On
RewriteBase /
<Files .*>
Order Deny,Allow
Deny From All
</Files>
RewriteCond %{HTTP_HOST} ^www\.(.+)$ [NC]
RewriteRule ^(.*)$ http://%1/$1 [R=301,L]
RewriteRule ^(?:application|modules|system)\b.* index.php/$0 [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI} !=/favicon.ico
RewriteCond %{REQUEST_URI} !=/robots.txt
RewriteRule .* index.php [L]
I've found solution by adding file robots.txt
User-agent: *
Disallow: /
Allow: /project
Analyzed by this site http://tools.seobook.com/robots-txt/analyzer/
Related
I've read many tutorials on rewriting the /page.php to /page but I cannot get this to work on my laravel website..
# do not allow anyone else to read your .htaccess file
<Files .htaccess>
deny from all
</Files>
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^([^/]+)/$ $1.php
RewriteRule ^([^/]+)/([^/]+)/$ /$1/$2.php
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI} !(\.[a-zA-Z0-9]{1,5}|/)$
RewriteRule (.*)$ /$1/ [R=301,L]
The url doesn't rewrite using this content in the .htaccess file. Am I making a schoolboy error?
In fact, the page never really finishes loading!
My main domain is tied to my public_html folder but I use an .htaccess redirect to change the root directory to a sub-directory in the folder to make it easier to host multiple sites. Example:
public_html
-- .htaccess
-- site1
---- .htaccess
-- site2
-- site3
The .htaccess file in the root directory is as follows:
RewriteEngine on
RewriteCond %{HTTP_HOST} ^(www.)?example.com$
RewriteCond %{REQUEST_URI} !^/subdirectory/
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ /subdirectory/$1
RewriteCond %{HTTP_HOST} ^(www.)?example.com$
RewriteRule ^(/)?$ subdirectory/ [L]
This works fine, but I think there are issues with this and the .htaccess file in my site1 directory. If I enter the URL it sometimes redirects to example.com/site1. So the website appears exactly the same on example.com and example.com/site1 but I don't want it to appear as example.com/site1. The second .htaccess file inside the site1 directory is show below.
RewriteEngine on
# Change default directory page
DirectoryIndex /home/
# Remove .php extension
RewriteCond %{THE_REQUEST} ^GET\ /[^?\s]+\.php
RewriteRule (.*)\.php$ /$1/ [L,R=301]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI} ^/(.+)/$
RewriteCond %{DOCUMENT_ROOT}/%1.php -f
RewriteRule ^(.*)/$ $1.php [L]
# Ensure all directory URLs have a trailing slash
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_URI} !\/$
RewriteCond %{REQUEST_URI} !\/[^\/]*\.[^\/]+$
RewriteRule .* http://%{HTTP_HOST}%{REQUEST_URI}/ [L,R=301]
# Same for HTTPS
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_URI} !\/$
RewriteCond %{REQUEST_URI} !\/[^\/]*\.[^\/]+$
RewriteRule .* https://%{HTTP_HOST}%{REQUEST_URI}/ [L,R=301]
# Redirect default error page to home page
RewriteCond %{QUERY_STRING} ^$
RewriteRule ^(/|error/)?$ /home/ [R=301,L]
# Error Documents
ErrorDocument 400 /error/?e=400
ErrorDocument 401 /error/?e=401
ErrorDocument 403 /error/?e=403
ErrorDocument 404 /error/?e=404
ErrorDocument 500 /error/?e=500
# Prevent viewing of htaccess file
<Files .htaccess>
order allow,deny
deny from all
</Files>
I'm not sure if it's an issue with the various rewrite rules I'm using that affects the URL, but I would appreciate any help if it can be resolved.
Thanks in advance and I apologise if my description isn't great.
Try
# Ensure all directory URLs have a trailing slash
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_URI} !\/$
RewriteCond %{REQUEST_URI} !\/[^\/]*\.[^\/]+$
RewriteRule ^(.*)$ http://%{HTTP_HOST}/$1/ [QSA,L,R=301]
# Same for HTTPS
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_URI} !\/$
RewriteCond %{REQUEST_URI} !\/[^\/]*\.[^\/]+$
RewriteRule ^(.*)$ https://%{HTTP_HOST}/$1 [QSA,L,R=301]
It works for me. %{REQUEST_URI} contains site1, so don't use it.
QSA adds any URL parameters like ?param1=val1¶m2=val2 If you don't use them, you may omit QSA.
Also while testing replace R=301 to R=302 (temporary redirect), else your browser remembers the rule and doesn't send request again.
We recently moved from a Clover site to a Wordpress site so the structure on our podcasts has changed. We have two podcast feeds, one for audio, and one for video.
The old podcast feeds were pulling in from these urls...
http://nmconline.net/podcast.php?pageID=27
http://nmconline.net/podcast.php?pageID=28
Our new feeds are sitting at...
http://nmc.church/feed/videopodcast
http://nmc.church/feed/audiopodcast
I've tried the redirect a few different ways but still no luck. I've tried using a straight 301 redirect and just recently move to a RewriteRule, but still won't work. Not sure if its important or not, but I am forwarding the old nmconline.net domain to our new nmc.church domain.
Here is my current .htaccess file.
# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^podcast\.php?pageID=27 http://nmc.church/feed/videopodcast [R=301,L]
RewriteRule ^podcast\.php?pageID=28 http://nmc.church/feed/audiopodcast [R=301,L]
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>
# END WordPress
Thanks in advance!
You cannot match QUERY_STRING in a RewriteRule. Here is how you can do:
# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteCond %{QUERY_STRING} ^pageID=27$ [NC]
RewriteRule ^podcast\.php$ http://nmc.church/feed/videopodcast? [R=301,L]
RewriteCond %{QUERY_STRING} ^pageID=28$ [NC]
RewriteRule ^podcast\.php$ http://nmc.church/feed/audiopodcast? [R=301,L]
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>
# END WordPress
? at the end of URL will remove previous query string.
I'm developing a web site that supports multiple languages (english and spanish) in PHP using parameters like this:
www.website.com/contact?lang=en
www.website.com/contact?lang=es
Yes, without extension .php...
I know that is a bad practice, so I want to have this:
www.website.com/en/contact
www.website.com/es/contact
I read other posts here in stackoverflow but, I don't want to use a PHP framework, and I read that I have to use Mod Rewrite (again because I already use it for remove the extension). In fact, I read this post (and others too), but nothing works.
When it is done, I read in google pages that I have to use:
<link rel="alternate" href="http://www.website.com/" hreflang="x-default" />
is this correct?
Thanks
EDIT 1:
The content of my .htaccess is:
RewriteBase /
#Prevent directory listing
Options All -Indexes
#Disable Etags
Header unset ETag
FileETag None
#Prevent viewing of .htaccess
<Files ~ "^.*\.([Hh][Tt][Aa])">
order allow,deny
deny from all
</Files>
RewriteEngine on
#Redirect non-www/www
RewriteCond %{HTTP_HOST} !^www\.(.*)$ [NC]
RewriteRule ^(.*)$ http://www.%{HTTP_HOST}/$1 [R=301,L]
#RewriteCond %{HTTPS} off
#RewriteCond %{HTTP_HOST} !^www\.(.*)$ [NC]
#RewriteRule ^(.*)$ http://www.%{HTTP_HOST}/$1 [R=301,L]
Options +FollowSymlinks -MultiViews
#Rewrite url
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}.php -f
RewriteRule ^(.*)$ $1.php
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}.html -f
RewriteRule ^(.*)$ $1.html
RewriteCond %{REQUEST_FILENAME} -f [OR]
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule .* - [L]
RewriteRule ^([^/]+)/([^/]+) /$2?lang=$1 [L,NC,QSA]
even if you use the solution from the post you marked out with a tiny adaption to meet your missing php file endings:
Options +FollowSymlinks -MultiViews
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} -f [OR]
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule .* - [L]
RewriteRule ^([^/]+)/([^/]+) /$2?lang=$1 [L,NC,QSA]
This should be your full .htaccess with a new rule to redirect lang specific URLs:
#Disable Etags
Header unset ETag
FileETag None
#Prevent viewing of .htaccess
<Files ~ "^.*\.([Hh][Tt][Aa])">
order allow,deny
deny from all
</Files>
Options All -Indexes -MultiViews
RewriteEngine on
RewriteBase /
#Redirect non-www/www
RewriteCond %{HTTP_HOST} !^www\. [NC]
RewriteRule ^(.*)$ http://www.%{HTTP_HOST}/$1 [R=301,L]
# redirect /contact?lang=en to /en/contact
RewriteCond %{THE_REQUEST} /+([^?]+?)(?:\.php)?\?lang=([^\s&]+) [NC]
RewriteRule ^ /%2/%1? [R=301,L,NE]
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}.php -f
RewriteRule ^(.+?)/?$ $1.php [L]
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}.html -f
RewriteRule ^(.+?)/?$ $1.html [L]
RewriteCond %{REQUEST_FILENAME} -f [OR]
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule . - [L]
RewriteRule ^([^/]+)/([^/]+) $2?lang=$1 [L,QSA]
This should take care of the redirects. You'll need to modify your links as #w3d has stated.
RewriteCond %{QUERY_STRING} ^lang=(en|es)$ [NC]
RewriteRule ^contact$ /%1/contact? [R=301,L]
The | in the query string means 'or' if you want other languages you can add them in there or you could change it to the less safe .*.
This is similar to question mod_rewrite: Being redirected to root folder; I want it to stay in sub-folder
but the answer there is not working for me.
I have a main site which redirects via an index.php handler, but I want a pre-live test area which is held in a subdirectory /UA/
I need requests for UA/ to pass through and be handled in the sub directory, I have tried both RewriteRule ^/UA - [L] and RewriteCond %{REQUEST_URI} !^/UA in my .htaccess of the main directory but this hasn't worked. I've tried with/without /'s
Here are my two .htaccess files:
RewriteEngine on
ReWriteBase /
# Redirect to HTTPS site
RewriteCond %{HTTP_HOST} ^my\-site\.com$ [OR]
RewriteCond %{HTTP_HOST} ^www\.my\-site\.com$
RewriteRule ^/?$ "https\:\/\/www\.mysite\.com\/" [R=301,L]
RewriteCond %{HTTP_HOST} ^mysite\.com$ [OR]
RewriteCond %{HTTP_HOST} ^www\.mysite\.com$
RewriteRule ^/?$ "https\:\/\/www\.mysite\.com\/" [R=301,L]
#Allow UA access
RewriteRule ^/UA - [L]
#Allow certain file types to access directly
RewriteRule \.(css|js|png|jpg|gif|woff|eot|ttf|svg|ico)$ - [L]
# Catch all
RewriteCond %{REQUEST_URI} !^/UA
RewriteRule .* index.php [L]
RewriteEngine on
ReWriteBase /UA/
#Allow certain file types to access directly
RewriteRule \.(css|js|png|jpg|gif|woff|eot|ttf|svg|ico)$ - [L]
# Catch all
RewriteRule .* index.php [L]
The problem is that the site continues to direct to the Live index.php version not the one in /UA/ with a URI of https://www.mysite/UA/
Add this line to always have directory slash on in your root .htaccess:
DirectorySlash On
Keep /UA/.htaccess like this:
RewriteEngine on
ReWriteBase /UA/
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI} !\.(css|js|png|jpg|gif|woff|eot|ttf|svg|ico)$ [NC]
RewriteRule ^ index.php [L]