Could anyone please tell me what the below code does?
RewriteEngine On
RewriteCond %{HTTP_HOST} ^example-old.com$
RewriteRule (.*) http://www.example-new.com/$1 [R=301,L]
Does it work only if someone types exactly example-old.com? What would happen to the URLs with folders, like example-old.com/folder1 and example-old.com/folder1/sub1/page1.php
One of my client's website has become a disaster. Following is the code in .htaccess and pages on Google search when opened, it adds an extra '/' at the end of every URL which displays a horrendous page. I am unable to figure out where the error in code is:
Options -Indexes
RewriteEngine On
RewriteCond %{HTTP_HOST} ^example-old.com$
RewriteRule (.*) http://www.example-new.com/$1 [R=301,L]
RewriteCond %{HTTP_HOST} ^www.example-old.com$
RewriteRule (.*) http://www.example-new.com/$1 [R=301,L]
RewriteCond %{HTTP_HOST} ^example-new.com$
RewriteRule (.*) http://www.example-new.com/$1 [R=301,L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . index.php [L]
# remove browser bugs
BrowserMatch ^Mozilla/4 gzip-only-text/html
BrowserMatch ^Mozilla/4\.0[678] no-gzip
BrowserMatch \bMSIE !no-gzip !gzip-only-text/html
Header append Vary User-Agent
RewriteCond %{HTTP_HOST} ^example-old\.com$ [OR]
RewriteCond %{HTTP_HOST} ^www\.example-old\.com$
RewriteRule ^2015\/?(.*)$ "http\:\/\/www\.example-old\.com\/$1" [R=301,L]
Instead of opening a page with the URL:-
http://www.example-new.com/folder1/page1.php
It opens:
http://www.example-new.com/folder1/page1.php/
I'm using example-old and example-new due to security reasons. Please help...!
RewriteEngine On
RewriteCond %{HTTP_HOST} ^example-old.com$
RewriteRule (.*) http://www.example-new.com/$1 [R=301,L]
This permanently redirects example.com/foo/foobar to example-new.com/foo/foobar
RewriteCond %{HTTP_HOST} ^example-old.com$
RewriteRule (.*) http://www.example-new.com/$1 [R=301,L]
in php context, you would use
if(host == "example.com" and Request_uri== "any request")
{header('location : host/Request_uri',301)
else
{no redirection}
Related
I have a URL: example.com/files/console/
I want it to be: example.com/console/
But at the same time, the console folder has it's own set of URLs.
This is my current htaccess rewrite section:
<IfModule mod_rewrite.c>
RewriteCond %{HTTPS} !=on
RewriteRule ^ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php [L,E=Cache-Control:max-age=12000]
RewriteRule ^files/(.*)$ files/console/$1 [L,R=301]
SetEnvIfNoCase Request_URI "(.*)" no-gzip -vary
</IfModule>
This doesn't work. I have 1 file in the root directory called index.php which handles all front end site requests which is working flawlessly. I then want to build the backend, whilst keeping the folder structure tidy hence the /files/ directory.
So I want to remove the files/ directory from the URL where .com/console/blog.php would read .com/console/blog and run the correct file...
I've been on so many topics here already, tested everyone's "working code" it just doesn't work.
You may try these rules in your site root .htaccess:
SetEnvIfNoCase Request_URI "(.*)" no-gzip -vary
RewriteEngine On
RewriteBase /
RewriteCond %{HTTPS} !=on
RewriteRule ^ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
RewriteRule ^console/ files%{REQUEST_URI} [L,NC]
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{DOCUMENT_ROOT}/$1.php -f
RewriteRule ^(.+?)/?$ $1.php [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php [L,QSA,E=Cache-Control:max-age=12000]
I have my site running on all over SSL, but I added a games sections which uses the 3rd party games in flash. When I enable SSL it stop working. I am wondersing if how can I only disable the SSL on that specific page which contains "/game/" in the url so that the games will work fine.
I tried this code from insternet in my .htaccess file but not working:
RewriteCond %{HTTPS} off
RewriteRule ^game^ http://%{HTTP_HOST}%{REQUEST_URI} [R=301,L]
EDIT:
I tried the answer suggested:
RewriteEngine On
RewriteCond %{HTTPS} On [NC]
RewriteRule ^game http://%{HTTP_HOST}%{REQUEST_URI} [R=301,L,NC]
It works but when I go the pages contained the word "game" it turns the other pages also to "http" and other pages are become using "http" instead of "https"
Then I tried this:
RewriteEngine On
RewriteCond %{HTTPS} !=on
RewriteRule ^ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
RewriteCond %{HTTPS} On [NC]
RewriteRule ^game http://%{HTTP_HOST}%{REQUEST_URI} [R=301,L,NC]
This it starts giving me the message "Page is not redirecting properly" when I go to "game" page url.
I want only the "game" pages to use "http".
EDIT TWO: The FULL .htaccess file
<IfModule mod_rewrite.c>
Options +FollowSymLinks
RewriteEngine On
RewriteCond %{HTTPS} !=on
RewriteRule ^ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
# Get rid of index.php
RewriteCond %{REQUEST_URI} /index\.php
RewriteRule (.*) index.php?rewrite=2 [L,QSA]
# Rewrite all directory-looking urls
RewriteCond %{REQUEST_URI} /$
RewriteRule (.*) index.php?rewrite=1 [L,QSA]
# Try to route missing files
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} public\/ [OR]
RewriteCond %{REQUEST_FILENAME} \.(jpg|gif|png|ico|flv|htm|html|php|css|js)$
RewriteRule . - [L]
# If the file doesn't exist, rewrite to index
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php?rewrite=1 [L,QSA]
</IfModule>
# sends requests /index.php/path/to/module/ to "index.php"
# AcceptPathInfo On
# #todo This may not be effective in some cases
FileETag Size
<IfModule mod_deflate.c>
AddOutputFilterByType DEFLATE text/text text/html text/plain text/xml text/css application/x-javascript application/javascript
</IfModule>
Need help. Let me know if any duplicate is found, I can not find anyone though.
Thanks.
This should be your full .htaccess:
<IfModule mod_rewrite.c>
Options +FollowSymLinks
RewriteEngine On
# except for /game/ enforce https
RewriteCond %{HTTPS} off
RewriteCond %{THE_REQUEST} !/game/ [NC]
RewriteRule ^ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
# for /game/ enforce http
RewriteCond %{HTTPS} on
RewriteCond %{THE_REQUEST} /game/ [NC]
RewriteRule ^ http://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
# Get rid of index.php
RewriteCond %{REQUEST_URI} /index\.php
RewriteRule (.*) index.php?rewrite=2 [L,QSA]
# Try to route missing files
RewriteCond %{REQUEST_FILENAME} public [OR]
RewriteCond %{REQUEST_URI} \.(jpg|gif|png|ico|flv|htm|html|php|css|js)$
RewriteRule . - [L]
# If the file doesn't exist, rewrite to index
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php?rewrite=1 [L,QSA]
</IfModule>
Make sure to clear your browser cache before testing this change.
I have a strange issue where pages are redirecting to the homepage. Let me explain - my website is thedj.com.au
Now when I type in www.thedj.com.au/payments it redirects to thedj.com.au (even though it should be going to the page https://thedj.com.au/payments).
Any idea why this is and how to fix?
My htaccess file is below:
# BEGIN HTTPS Redirection Plugin
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteRule ^home.htm$ https://thedj.com.au/ [R=301,L]
RewriteRule ^photos.htm$ http://photos.thedj.com.au/ [R=301,L]
RewriteRule ^contacts.htm$ https://thedj.com.au/contact-us/ [R=301,L]
RewriteRule ^booking.htm$ https://thedj.com.au/book-dj/ [R=301,L]
RewriteRule ^downloads.htm$ https://thedj.com.au/downloads/ [R=301,L]
RewriteRule ^payonline.htm$ https://thedj.com.au/payments/ [R=301,L]
RewriteRule ^price.htm$ https://thedj.com.au/pricing/ [R=301,L]
RewriteRule ^questions.htm$ https://thedj.com.au/faq/ [R=301,L]
RewriteRule ^links.htm$ https://thedj.com.au/links/ [R=301,L]
RewriteRule ^thankyous/index.htm$ https://thedj.com.au/testimonials/ [R=301,L]
RewriteCond %{HTTPS} off
RewriteRule ^(.*)$ https://thedj.com.au/ [L,R=301]
</IfModule>
# END HTTPS Redirection Plugin
# 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
RewriteCond %{HTTP_HOST} ^mrdj\.net\.au$ [OR]
RewriteCond %{HTTP_HOST} ^www\.mrdj\.net\.au$
RewriteRule ^/?$ "https\:\/\/thedj\.com\.au\/" [R=301,L]
RewriteCond %{HTTP_HOST} ^mrdj\.com\.au$ [OR]
RewriteCond %{HTTP_HOST} ^www\.mrdj\.com\.au$
RewriteRule ^/?$ "https\:\/\/thedj\.com\.au\/" [R=301,L]
RewriteCond %{HTTP_HOST} ^thedjs\.com\.au$ [OR]
RewriteCond %{HTTP_HOST} ^www\.thedjs\.com\.au$
RewriteRule ^/?$ "https\:\/\/thedj\.com\.au\/" [R=301,L]
RewriteCond %{HTTP_HOST} ^theperthweddingdjs\.com$ [OR]
RewriteCond %{HTTP_HOST} ^www\.theperthweddingdjs\.com$
RewriteRule ^/?$ "https\:\/\/thedj\.com\.au\/" [R=301,L]
RewriteCond %{HTTP_HOST} ^thedjs\.net\.au$ [OR]
RewriteCond %{HTTP_HOST} ^www\.thedjs\.net\.au$
RewriteRule ^/?$ "https\:\/\/thedj\.com\.au" [R=301,L]
Note:
I've tried commenting out the lines
#RewriteCond %{HTTPS} off
#RewriteRule ^(.*)$ https://thedj.com.au/ [L,R=301]
However this has not fixed the issue. I'm thinking this may perhaps be because the website is entirely https:// - but any more ideas would be much appreciated.
Best,
Kosta
The .htaccess shouldn't do any redirect here.
For testing, this website could be useful.
Is this configuration from your live site? Because https://thedj.com.au/payments works for me.
Browsers tend to cache permanent redirects quite aggressively. You need to clear the complete cache or use the private browsing mode to test a redirect again. (But you need to close ALL private browsing windows and then open a new one)
I am trying and googling for hours now and can't find a solution for my problem. I want to rewrite:
domain.com/profile.php?user=abc > domain.com/abc
I use:
RewriteRule ^(.*)/$ /profile.php?user=$1 [L]
which works only with a slash at the end. If i try it without the slash
RewriteRule ^(.*)$ /profile.php?user=$1 [L]
I get an Internal Server Error!
Complete .htaccess
ErrorDocument 404 /errors/404.php
ErrorDocument 500 /errors/500.php
RewriteEngine On
RewriteCond %{HTTP_HOST} ^www\.domain\.com$ [NC]
RewriteCond %{REQUEST_URI} !\.(css|jpg|gif|png|jar|js|html|htm|php)$
RewriteRule ^(.*)$ http://domain.com/$1 [L,R=301]
RewriteRule ^share/([^/]*)/$ /share/share.php?id=$1 [L]
RewriteRule ^(.*)/$ /profile.php?user=$1 [L]
<IfModule mod_deflate.c>
<FilesMatch "\.(html|php|txt|xml|js|css|svg)$">
SetOutputFilter DEFLATE
</FilesMatch>
</IfModule>
BrowserMatch ^Mozilla/4\.0[678] no-gzip
BrowserMatch \bMSIE\s7 !no-gzip !gzip-only-text/html
Someboy have an idea what Im doing wrong?
Thanks,
Kornel
With your second try, you get a 500 because you create an infinite loop:
^(.*)$ will match profile.php?user=xxx again and again... Which is not the case when you try with ^(.*)/$ because (no trailing slash) this won't match profile.php?user=xxx
Instead, you can have it this way
RewriteEngine On
RewriteCond %{HTTP_HOST} ^www\.domain\.com$ [NC]
RewriteCond %{REQUEST_URI} !\.(css|jpg|gif|png|jar|js|html|htm|php)$
RewriteRule ^(.*)$ http://domain.com/$1 [L,R=301]
RewriteRule ^share/([^/]*)/$ /share/share.php?id=$1 [L]
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)/?$ /profile.php?user=$1 [L]
I've been checking around but I can't seem to find the exact syntax to achieve what I'm trying.
I'm currently renewing a website, but as it has pretty good positions in Google I want to preserve all the links, but this time I want to use pretty url's. So, the problem I'm having is the following:
I have this bases-generales (general-rules) section and I use this to Rewrite:
RewriteRule ^bases-generales/ bases.php?locale=es_LA
The problem I'm having is that the current (old) file is named bases.php, so I want users to be redirected to /bases-generales/ when they open bases.php directly from Google or some other link.
The rule I'm using at the moment is:
RewriteRule /bases.php http://mysite/bases-generales/ [R=301,L]
Now, this command does redirect, but the only problem is that the url looks like this:
http://mysite/bases-generales/?locale=es_LA
And the other problem is that it causes a Redirect Loop.
For more information this is the complete htaccess (mysite is fake of course)
<Files ~ "^\.(htaccess|htpasswd)$">
deny from all
</Files>
order deny,allow
RewriteEngine on
RewriteCond %{HTTP_HOST} ^(mysite)(:80)? [NC]
RewriteRule ^(.*) http://mysite/$1 [R=301,L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_URI} !(.*)/$
RewriteRule ^(.*)$ http://mysite/$1/ [L,R=301]
RewriteCond %{SCRIPT_FILENAME} !-d
RewriteCond %{SCRIPT_FILENAME} !-f
RewriteBase /
RewriteRule ^/ index.php?locale=es_LA
RewriteRule ^bases-generales/ bases.php?locale=es_LA
RewriteRule ^condiciones/ condiciones.php?locale=es_LA
RewriteRule ^programa/ programa.php?locale=es_LA
RewriteRule ^premios/ premios.php?locale=es_LA
RewriteRule ^ganadores/ ganadores.php?locale=es_LA
RewriteRule ^patrocinadores/ patrocinadores.php?locale=es_LA
RewriteRule ^galeria/ galeria.php?locale=es_LA
RewriteRule ^contacto/ contacto.php?locale=es_LA
RewriteRule ^bases.php http://mysite/bases-generales/ [R=301,L]
concerning your first request, you have to append ? to the new url in order to prevent Rewrite_mod from adding the querystring, so the directive will be
RewriteRule ^bases.php http://mysite/bases-generales/? [R=301,L]
2) you should add L to your rewrite rules to stop processing the url :
RewriteRule ^bases-generales/ bases.php?locale=es_LA [L]
the htaccess will be:
<Files ~ "^\.(htaccess|htpasswd)$">
deny from all
</Files>
order deny,allow
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_URI} !(.*)/$
RewriteRule ^(.*)$ http://mysite/$1/ [L,R=301]
RewriteBase /
RewriteRule ^bases.php http://mysite/bases-generales/? [R=301,L]
RewriteRule ^sample2.php http://mysite/sample2/? [R=301,L]
RewriteRule ^bases-generales/ bases.php?locale=es_LA [L]
RewriteRule ^sample2/ sample2.php?locale=xx [L]