I want to do my subdomains working with subdirectories without redirection.
I write this:
RewriteCond %{HTTP_HOST} ^(www\.)?mysubdomain\.site\.com$ [NC]
RewriteCond %{REQUEST_URI} !^/cities/mysubdomain/
RewriteRule ^(.*)$ /cities/mysubdomain/$1%{REQUEST_URI} [L]
It works good with mysubdomain.site.com, but all files inside directory not working. For example mysubdomain.site.com/robots.txt open site.com/robots.txt not site.com/cities/subdomain/robots.txt (that what I want)
Can you help with explanation?
My current .htaccess is:
Options -Indexes
ErrorDocument 404 /404.php
<IfModule mod_php5.c>
php_flag allow_call_time_pass_reference 1
php_flag session.use_trans_sid off
#php_value display_errors 1
#php_value mbstring.func_overload 2
#php_value mbstring.internal_encoding UTF-8
</IfModule>
<IfModule mod_rewrite.c>
Options +FollowSymLinks
RewriteEngine On
RewriteBase /
RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /index\.php\ HTTP/
RewriteRule ^index\.php$ http://example.com [R=301,L]
# sub-domain redirect
RewriteCond %{HTTP_HOST} ^(www\.)?sub\.example\.com$ [NC]
RewriteCond %{REQUEST_URI} !^/cities/barnaul/ [NC]
RewriteRule ^(.*)$ /cities/barnaul/$1 [L,QSA]
# sub-domain redirect
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-l
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !/bitrix/urlrewrite.php$
RewriteRule ^(.*)$ /bitrix/urlrewrite.php [L]
RewriteRule .* - [E=REMOTE_USER:%{HTTP:Authorization}]
</IfModule>
<IfModule mod_expires.c>
ExpiresActive on
ExpiresByType image/jpeg "access plus 3 day"
ExpiresByType image/gif "access plus 3 day"
</IfModule>
RewriteCond %{HTTP_HOST} ^www.example.com$ [NC]
RewriteRule ^(.*)$ http://example.com$1 [R=301,L]
Redirect 301 /cities/sms-sending-samara.php http://sub.example.com
Redirect 301 /information/sms_directing.php http://example.com/#sms_directing
Redirect 301 /sitemap_000.xml http://example.com/sitemap.xml
Redirect 301 /information/information.php http://example.com/information/
Redirect 301 /help/%D0%9C%D0%BE%D0%B4%D1%83%D0%BB%D1%8C%201%D0%A1%20v8.2.pdf http://example.com/api/modul_1c.php
Redirect 301 /help/Модуль%201С%20v8.2.pdf http://example.com/api/modul_1c.php
Redirect 301 /api/modul.php http://example.com/api/modul_1c.php
Redirect 301 /help/HTTP.pdf http://example.com/api/prot_http.php
Redirect 301 /help/SMPP.pdf http://example.com/api/prot_smpp.php
Redirect 301 /help/SMTP.pdf http://example.com/api/prot_smtp.php
Redirect 301 /help/SOAP.pdf http://example.com/api/prot_soap.php
Redirect 301 /help/XML.pdf http://example.com/api/prot_xml.php
Redirect 301 /API/prot_http.php http://example.com/api/prot_http.php
Redirect 301 /API/prot_smpp.php http://example.com/api/prot_smpp.php
Redirect 301 /API/prot_smtp.php http://example.com/api/prot_smtp.php
Redirect 301 /API/prot_soap.php http://example.com/api/prot_soap.php
Redirect 301 /API/prot_xml.php http://example.com/api/prot_xml.php
Redirect 301 /rassilka_sms_internet.html http://example.com/rassilka_sms_cherez_internet.html
Redirect 301 /sms_rassilka_cherez_internet_01.html http://example.com/rassilka_sms_cherez_internet.html
Redirect 301 /internet_rassilka_sms.html http://example.com/rassilka_sms_cherez_internet.html
Redirect 301 /sms_uvedomlenie_2.html http://example.com/sms_uvedomlenie.html
Redirect 301 /sms_uslugi_2.html http://example.com/sms_uslugi.html
Redirect 301 /sms_rassilka_reklamy_01.html http://example.com/sms_rassilka_reklamy.html
Redirect 301 /sms_rassilka_03.html http://example.com
Redirect 301 /sms_rassilka.html http://example.com
Redirect 301 /rassilka_sms_02.html http://example.com
Redirect 301 /rassilki_sms_01.html http://example.com
Redirect 301 /sms_reklama.html http://example.com/information/reklama.php
Redirect 301 /sms_rassilka_deshevo.html http://example.com/rassilka_sms_deshego.html
Redirect 301 /sms_rassilka_deshevo01.html http://example.com/rassilka_sms_deshego.html
Redirect 301 /rassilka_sms_internet.html http://example.com/rassilka_sms_cherez_internet.html
Redirect 301 /programma_cmc.html http://example.com/programma_sms.html
Redirect 301 /korporativnye_sms.htm http://example.com/korporativnye_sms.html
Redirect 301 /information/sector/index.php http://example.com/reshenia/
Redirect 301 /massovaya_rassilka_sms.html http://example.com
Redirect 301 /API/ http://example.com/api/
Redirect 301 /API http://example.com/api/
Redirect 301 /sms_trafik.htm http://example.com/smstrafik.html
Redirect 301 /sms_shluz.htm http://example.com/smsshluz.html
Redirect 301 /sms_trafik.html http://example.com/smstrafik.html
Redirect 301 /sms_shluz.html http://example.com/smsshluz.html
Redirect 301 /information/sms_reklama.php http://example.com/information/reklama.php
Redirect 301 /rassilka_ http://example.com
Redirect 301 /information/ackciya.php http://example.com/information/post_akciya.php
Redirect 301 /information/akciya.php http://example.com/information/post_akciya.php
Redirect 301 /information/sector/gov/ http://example.com/reshenia/gosstruktury/
Redirect 301 /information/sector/ http://example.com/reshenia/
Redirect 301 /information/MMS_directing.php http://example.com
Redirect 301 /information/WAP_directing.php http://example.com
Redirect 301 /information/voice_directing.php http://example.com
Redirect 301 /mobilny_marketing.html http://example.com/mobilnymarketing.html
Redirect 301 /cities/sms-sending-belgorod.php http://sub.example.com
AddDefaultCharset cp1251
Related
I have just redone my site from WordPress to html and set it to non-www from www.
My redirects are playing up though.
My htaccess is set up as:
RewriteEngine On
RewriteCond %{HTTP_HOST} ^www\.(.*)$ [NC]
RewriteRule ^(.*)$ http://%1/$1 [L,R=301]
RewriteRule ^index.html$ / [NC,R,L]
Redirect 301 /category/wp-page-name/ https://domain-name/page-name.html
The 301 is redirecting to:
https://domain-name/page-name.htmlwp-page-name
it is appending the old WordPress page name to the re-directed address.
I have tried:
RedirectMatch 301 ^/category/wp-page-name/?$ https://domain-name/page-name.html
and
RewriteRule ^/?category/wp-page-name/?$ https://domain-name/page-name.html [L,R=301]
No redirect occurs although I am not sure whether the initial faulty redirects have been cached.
I would be grateful for any advice
I tried the following code to redirect one URL to another.
# 301 Redirect URLs.
Redirect 301 /sat http://sample.org/example
Redirect 301 /gre http://sample.org/example
Redirect 301 /ielts-sat http://sample.org/example
Redirect 301 /ielts http://sample.org/example
Result is,
When I try this link -
http://sample.org/sat
it redirecting to
http://sample.org/example/?/sat
I am attaching whole .htaccess code down here,
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ /index.php?/$1 [L]
RewriteCond %{THE_REQUEST} ^GET.*index\.php [NC]
RewriteRule (.*?)index\.php/*(.*) /$1$2 [R=301,NE,L]
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond $1 !^(index\.php)
RewriteRule ^(.+)$ index.php?$1 [PT,L,QSA]
# Deny accessing below extensions
<Files ~ "(.json|.lock|.git|.bat|.md)">
Order allow,deny
Deny from all
</Files>
<Files robots.txt>
Order deny,allow
Allow from all
</Files>
# Deny accessing dot files
RewriteRule (^\.|/\.) - [F]
# 301 Redirect URLs.
Redirect 301 /sat http://sample.org/example
Redirect 301 /gre http://sample.org/example
Redirect 301 /ielts-sat http://sample.org/example
Redirect 301 /ielts http://sample.org/example
Could anybody here help me, please?
How to 301 redirect domain.com/ to domain.com so if someone open domain.com/ with / on end we need 301 redirect to domain.com without / on end, and this need affect on all pages:
domain.com/username/ to domain.com/username
domain.com/tag/lol/ to domain.com/tag/lol
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)/$ /$1 [L,R=301]
SOURCE: Htaccess: add/remove trailing slash from URL
Whenever these 301 redirects are added to a .htaccess file (content follows) I get a 500 Internal Sever error - and idea why?
Much thanks in advance...
Richard
# 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
# BEGIN Permanent URL redirects
Redirect 301 /about-cs.html www.christian-simpson.com/about-christian-simpson/
Redirect 301 /entrepreneurial-success.html www.christian-simpson.com/entrepreneurial-success/
Redirect 301 /advanced-thinking.html www.christian-simpson.com/advanced-thinking/
Redirect 301 /become-a-coach.html www.christian-simpson.com/become-a-coach/
Redirect 301 /speaking.html www.christian-simpson.com/speaking/
Redirect 301 /resources.html www.christian-simpson.com/resources/
Redirect 301 /praise.html www.christian-simpson.com/testimonials/
Redirect 301 /store.html www.christian-simpson.com/store/
Redirect 301 /contact.html www.christian-simpson.com/contact/
Redirect 301 /privacy.html www.christian-simpson.com/privacy-policy/
Redirect 301 /anti-spam.html www.christian-simpson.com/anti-spam-policy/
Redirect 301 /terms.html www.christian-simpson.com/terms-of-service/
# END Permanent URL redirects
There are few problems:
Mixing of mod_alias and mod_rewrite rules.
Not using http:// in target URI.
Keeping redirect rule after rewrite ones.
To fix this you can use:
# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
# BEGIN Permanent URL redirects
RewriteRule ^about-cs\.html$ /about-christian-simpson/? [L,R=301,NC]
RewriteRule ^entrepreneurial-success\.html$ /entrepreneurial-success/? [L,R=301,NC]
# other 301 rules here
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>
# END WordPress
I site that I've inherited for some reason was set up with www- as well as www.
To clarify, both of these URLs work:
http://www-mcr.trinhall.cam.ac.uk
http://www.mcr.trinhall.cam.ac.uk
I want to get all traffic using the www- to redirect to the www.
I thought that I'd nailed it with the following htaccess rules, but they don't seem to be working. Any help would be much appreciated!
RewriteEngine On
RewriteCond %{HTTP_HOST} !^www.mcr.trinhall.cam.ac.uk$ [NC]
RewriteRule ^(.*)$ http://www.mcr.trinhall.cam.ac.uk/$1 [L,R=301]
The full .htaccess file is below:
RewriteEngine On
RewriteCond %{HTTP_HOST} !^www.mcr.trinhall.cam.ac.uk$ [NC]
RewriteRule ^(.*)$ http://www.mcr.trinhall.cam.ac.uk/$1 [L,R=301]
RedirectMatch 301 ^/wiki/International_Students http://www.mcr.trinhall.cam.ac.uk/prospective-students/international/
RedirectMatch 301 ^/wiki/McMenemy_Seminar http://www.mcr.trinhall.cam.ac.uk/academics/mcmenemy-seminars/
RedirectMatch 301 ^/wiki/Welfare http://www.mcr.trinhall.cam.ac.uk/welfare/counselling/
RedirectMatch 301 ^/wiki/Transportation http://www.mcr.trinhall.cam.ac.uk/prospective-students/getting-around/
RedirectMatch 301 ^/wiki/Grants http://www.mcr.trinhall.cam.ac.uk/college-support/grants-and-funding/
RedirectMatch 301 ^/wiki/Grants_and_Funding http://www.mcr.trinhall.cam.ac.uk/college-support/grants-and-funding/
RedirectMatch 301 ^/wiki/Cake http://www.mcr.trinhall.cam.ac.uk/welfare/peer-support/
RedirectMatch 301 ^/wiki/Disability_Access http://www.mcr.trinhall.cam.ac.uk/welfare/students-with-disabilities/
RedirectMatch 301 ^/wiki/Recycling_Instructions http://www.mcr.trinhall.cam.ac.uk/current-college-residents/green/
RedirectMatch 301 ^/wiki/Bateman_Street http://www.mcr.trinhall.cam.ac.uk/prospective-students/accommodation/
RedirectMatch 301 ^/wiki/Life_in_Cambridge http://www.mcr.trinhall.cam.ac.uk/prospective-students/eating-in-cambridge/
RedirectMatch 301 ^/wiki/Prospective_Students http://www.mcr.trinhall.cam.ac.uk/prospective-students/accommodation/
RedirectMatch 301 ^/wiki/Leslie_Stephen_Room http://www.mcr.trinhall.cam.ac.uk/college-facilities/function-rooms/
RedirectMatch 301 ^/wiki/Dining http://www.mcr.trinhall.cam.ac.uk/dining-in-college/formal-dinners/
RedirectMatch 301 ^/wiki/Mailing_list http://www.mcr.trinhall.cam.ac.uk/your-mcr/mailing-lists/
RedirectMatch 301 ^/wiki/MCR_Committee http://www.mcr.trinhall.cam.ac.uk/your-mcr/committee/
#RedirectMatch 301 ^/wiki/ http://www.mcr.trinhall.cam.ac.uk/
# 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
The problem is in this line:
RewriteCond %{HTTP_HOST} !^www.mcr.trinhall.cam.ac.uk$ [NC]
You NEED to escape dot . character if you want to achieve what you want. In regular expressions the dot character means ANY character. You current regex will match www.mcr.trinhall.cam.ac.uk as well as www-mcr-trinhall-cam-ac-uk as well as www8mcr8trinhall8cam8ac8uk etc -- you have got the idea.
To solve it escape the dots:
RewriteCond %{HTTP_HOST} !^www\.mcr\.trinhall\.cam\.ac\.uk$ [NC]
or use non-regex match (plain string comparison):
RewriteCond %{HTTP_HOST} !=www.mcr.trinhall.cam.ac.uk [NC]