When there's 404 missing page error this URL is called:
https://domain.com/404/
Inside the 404 folder there is only a htaccess file that will redirect to language specific error pages (subfolders only with one index.html in them).
/
404
.htaccess
pt
index.html
en
index.html
htaccess file code:
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
# If Accept-Language starts with 'pt',
# then redirect (only) subdirectory 'pt'
RewriteCond %{HTTP:Accept-Language} ^pt [NC]
RewriteRule ^/?$ %{REQUEST_URI}pt [L,NC]
# Otherwise, redirect to en
RewriteRule ^/?$ %{REQUEST_URI}en [L,NC]
</IfModule>
The final URL looks like this for Portuguese for example: domain.com/404/pt/
What do I need to change so that the URL will still redirect to the index.html in the language specific subfolder but will look like domain.com/404(with or without trailing slash)?
Thank you.
For silent rewrites to language specific 404 use this .htaccess in /404/ sub-directory:
ErrorDocument 404 default
DirectoryIndex index.html
RewriteEngine On
RewriteBase /404/
# If Accept-Language starts with 'pt',
# then redirect (only) subdirectory 'pt'
RewriteCond %{HTTP:Accept-Language} ^pt [NC]
RewriteRule ^/?$ pt/index.html [L]
# Otherwise, redirect to en
RewriteRule ^/?$ en/index.html [L]
Related
I have htaccess file below
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}\.html -f
RewriteRule ^(.*)$ $1.html
Redirect /index.html /login.html
ErrorDocument 404 /404.html
ErrorDocument 403 /403.html
Options -Indexes
Redirect /index.html /login.html
When user enters index page it should redirect to login.html page.
But it doesn't work.
Redirect /index.html /login.html
im requesting /index
If you are requesting /index then I'm not sure why you are checking for /index.html in your rule. However, you should be using mod_rewrite to construct this redirect since you are already using mod_rewrite for your internal rewrites.
So, have it like this instead:
Options -Indexes
ErrorDocument 404 /404.html
ErrorDocument 403 /403.html
RewriteEngine On
RewriteBase /
# Redirect "/index" to "/login"
RewriteRule ^index$ /login [R=302,L]
# Append ".html" if target file exists
RewriteCond %{DOCUMENT_ROOT}/$1.html -f
RewriteRule (.*) $1.html [L]
I've also "fixed" your .html rewrite since this could result in a 500 error for certain requests and there's no need to check that the request does not map to a directory before checking that the request does map to a file.
See the following question on ServerFault that expands on this potential issue regarding .html removal. https://serverfault.com/questions/989333/using-apache-rewrite-rules-in-htaccess-to-remove-html-causing-a-500-error
I want to redirect several pages to a PHP page with GET variables. However, when I try to use an .htaccess file, it redirects but changes the URL. I don't want it to change the URL structure when redirecting. How would I do this?
For example, I want to redirect /fly-snooze-cruise to http://example.com/package_listing.php?package-type=fly-snooze-cruise
and /fly-snooze-cruise/orlando-airport to http://example.com/package_listing.php?package-type=fly-snooze-cruise&airport=orlando-airport
Here is my .htaccess code:
Options +FollowSymlinks -MultiViews
RewriteEngine On
RewriteBase /
RewriteRule ^fly-snooze-cruise$ http://www.example.com/package_listing.php?package-type=fly-snooze-cruise [L]
RewriteRule ^fly-snooze-cruise/orlando-airport$ http://www.example.com/package_listing.php?package-type=fly-snooze-cruise&airport=orlando-airport [L]
RewriteRule ^fly-snooze-cruise/orlando-sanford-airport$ http://www.example.com/package_listing.php?package-type=fly-snooze-cruise&airport=orlando-sanford-airport [L]
RewriteRule ^fly-snooze-cruise/melbourne-airport$ http://www.example.com/package_listing.php?package-type=fly-snooze-cruise&airport=melbourne-airport [L]
RewriteRule ^snooze-park-cruise$ http://www.example.com/package_listing.php?package-type=snooze-park-cruise [L]
The crawling properties of site showing
http://www.abc.com/http://www.abc.com/index.php?option=com_toys
http://www.abc.com/http://www.abc.com/index.php?option=com_article
http://www.abc.com/http://www.abc.com/index.php?option=com_play&view=category&vid=10
The site been crawled like this, with errors coming in as duplicate url. Correct url is
http://www.abc.com/index.php?option=com_toys
http://www.abc.com/index.php?option=com_article
http://www.abc.com/index.php?option=com_play&view=category&vid=10
is there any way to 301 redirect
i tried using
RewriteCond %{REQUEST_URI} ^.*/http://www.abc.com.*$
RewriteRule .* index.php [R=301,L]
But its not achieving the desired as redirecting to http://www.abc.com/index.php
How to redirect through htaccess from incorrect url to correct url sttructure off site
Enable mod_rewrite and .htaccess through httpd.conf and then put this code in your .htaccess under DOCUMENT_ROOT directory:
Options +FollowSymLinks -MultiViews
# Turn mod_rewrite on
RewriteEngine On
RewriteBase /
RewriteCond %{THE_REQUEST} ^[A-Z]{3,}\s/+http://.+?(/index\.php\?[^\s]+) [NC]
RewriteRule ^ %1 [R=301,L,NE]
Try this code :
RewriteEngine On
RewriteRule ^http://www.abc.com/index.php /index.php [QSA, R=301]
Google webmaster showing some duplicate url,
They are
www.abc.com/index.php?option=com_toys&view=detail&n_id=148&ite..
www.abc.com/index.php?option=com_toys&view=detail&n_id=156&item..
www.abc.com/index.php?option=com_games&view=detail&vid=170&itemid..
www.abc.com/index.php?option=com_play&view=detail&vid=175&it..
To remove them - i feel the best way is to redirect to home page for any url containing .. at end of url
tried putting this condition, but it does not work too
RewriteRule ^(.*)\.htm$ http://www.abc.com/$1 [R=301,L]
RewriteRule ^(.*)$ http://www.abc.com/$1 [L,R=301]
RewriteRule ^(..*)\.htm$ http://www.abc.com/$1 [R=301,L]
Correct url structure are
www.abc.com/index.php?option=com_toys&view=detail&n_id=148&Itemid=2
www.abc.com/index.php?option=com_toys&view=detail&n_id=156&Itemid=2
www.abc.com/index.php?option=com_games&view=detail&vid=170&Itemid=3
www.abc.com/index.php?option=com_play&view=detail&vid=175&Itemid=4
any suggestions pls ... many thnx
Edit on 13th Sep
Hello Anubhav,
If we have redirect these URL to 404 page then is below command in htaccess correct
RewriteCond %{THE_REQUEST} \?.+?\.\.
RewriteRule ^index\.php$ - [NC,L,R=404]
Enable mod_rewrite and .htaccess through httpd.conf and then put this code in your .htaccess under DOCUMENT_ROOT directory:
Options +FollowSymLinks -MultiViews
# Turn mod_rewrite on
RewriteEngine On
RewriteBase /
RewriteCond %{THE_REQUEST} \?.+?\.\.
RewriteRule ^ /? [R=301,L,NE]
In my htaccess file I have the following redirections:
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteCond %{HTTP_HOST} ^domain.com
RewriteRule ^(.*)$ http://www.domain.com/$1 [R=301,L]
RewriteRule index.html$ Controller/index.php [L]
</IfModule>
I want index.html (which does not exist) to be redirected to my controller.
index.php (which exists) should be my home page.
Now, my homepage is not working when typing http://www.domain.com/ in my browser. That URL redirects to my controller.
http://www.domain.com/index.php works fine, bringing my homepage.
How do I set index.php as my index file keeping my redirection for the controller?
If I've understood your situation correctly, you just want to specify DirectoryIndex in your .htaccess file so that it only points to index.php:
DirectoryIndex index.php
Between that and your rules, that leads to the following URL to file mappings:
http://www.example.com/ -> /index.php
http://www.example.com/index.php -> /index.php
http://www.example.com/index.html -> /Controller/index.php