I have in my .htaccess file the following code:
Options +FollowSymLinks
RewriteEngine On
Redirect 301 /index.asp http://www.website.com/index.php
Redirect 301 /contact.asp http://www.website.com/contact.php
RewriteCond %{REQUEST_METHOD} !POST
RewriteRule ^(.*/)?index\.([a-zA-Z0-9]{3,4})$ /$1 [R=301,L]
ErrorDocument 404 error.php
RewriteRule ^sitemap.xml sitemap.php
RewriteCond %{ENV:REDIRECT_STATUS} 200
RewriteRule .* - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI} ^(.*)$
RewriteRule (.*) seofile.php?word=%{REQUEST_URI}
Now,
for some reason, when I entry to contact.asp I'm getting
http://www.website.com/seofile.php?word=/contact.asp
how can I fix it?
Try using rewriterule instead of Redirect (I think rewrite rules are applied before redirect rules). So something like:
RewriteRule ^index.asp / [R=301,L]
RewriteRule ^contact.asp /contact.php [R=301,L]
PS. the first rule can be removed, as you already rewrite every index.xxx file.
Advice: try to separate things that don't belong to RewriteRules.
Try this code and please tell me if it works:
ErrorDocument 404 error.php
Options +FollowSymLinks
RewriteEngine On
RewriteRule ^(index|contact)\.asp $1.php [QSA,R=301,L]
RewriteRule ^sitemap\.xml$ sitemap.php [L]
RewriteCond %{REQUEST_METHOD} !POST
RewriteRule ^(.*/)?index\.([a-zA-Z0-9]{3,4})$ /$1 [R=301,L]
RewriteCond %{ENV:REDIRECT_STATUS} 200
RewriteRule (.*) - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule (.*) seofile.php?word=%{REQUEST_URI}
Related
I am trying to create .htaccess to create friendly url.
I have made some of the urls work but the others not working. I am using the following code in .htaccess file.
Options +FollowSymLinks
RewriteEngine On
RewriteCond %{HTTP_HOST} !^www.airporttransfer4u.co.uk$ [NC]
RewriteRule ^(.*)$ http://www.airporttransfer4u.co.uk/$1 [L,R=301]
RewriteCond %{HTTP_HOST} ^195\.20\.236\.228
RewriteRule (.*) http://www.airporttransfer4u.co.uk/$1 [R=301,L]
ErrorDocument 404 /404.php
RewriteBase /
RewriteCond %{REQUEST_URI} !^/admin/
RewriteCond %{REQUEST_URI} !\.(gif|jpg|png|css|js|etc|flv|swf|mp4|mov)$ [NC]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php?p=$1 [L,QSA]
RewriteRule ^recover/([^/]*)$ /recover.php?mode=$1 [L,QSA]
The url for recover.php is failing but index.php rule is working. Recover.php rule directing to 404 page.
I also have multple variable urls to convert to friendly url. Example
index.php?p=blog_item&id=52
Any idea why it is failing?
Have your rules in this order:
ErrorDocument 404 /404.php
Options +FollowSymLinks -MultiViews
RewriteEngine On
RewriteBase /
RewriteCond %{HTTP_HOST} !^www\.airporttransfer4u\.co\.uk$ [NC]
RewriteRule ^(.*)$ http://www.airporttransfer4u.co.uk/$1 [L,R=301]
RewriteRule ^recover/([^/]+)/?$ /recover.php?mode=$1 [L,QSA]
RewriteCond %{REQUEST_URI} !^/admin/
RewriteCond %{REQUEST_URI} !\.(gif|jpg|png|css|js|etc|flv|swf|mp4|mov)$ [NC]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.+)$ index.php?p=$1 [L,QSA]
I need to redirect all index.html like this
Original URL
www.example.com/lp/index.html
www.example.com/sytem/index.html
Desired URL
www.example.com/lp
www.example.com/sytem
I used the follwing, it redirects successfully but 404 page
RewriteEngine On
RewriteRule ^index\.html$ [R=301,L]
RewriteRule ^(.*)/index\.html$ /$1/ [R=301,L]
You almost got it right, what you did looks like a copy paste error to me. Your first RewriteRule is missing a parameter - there should be a slash before [R=301,L]
Your htaccess should look like this:
RewriteEngine On
RewriteRule ^index\.html$ / [R=301,L]
RewriteRule ^(.*)/index\.html$ /$1/ [R=301,L]
Reference:
http://dense13.com/blog/2012/10/29/removing-index-html-with-mod_rewrite-in-htaccess/
Place this code in your DOCUMENT_ROOT/.htaccess file:
DirectoryIndex index.html
RewriteEngine On
RewriteCond %{THE_REQUEST} /index\.html [NC]
RewriteRule ^(.*?)index\.html$ /$1 [L,R=301,NC,NE]
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{DOCUMENT_ROOT}/$1/index\.html -f [NC]
RewriteRule ^(.+?)/?$ /$1/index.html [L]
Try putting this in your .htaccess
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ $1/index\.html [PT,L]
PT and L are rewrite flags, for more details about them check http://httpd.apache.org/docs/2.2/rewrite/flags.html
why not redirect index.(anything) ? like index.php? index.xhtml?
RewriteEngine On
RewriteRule ^index\.(.*)$ / [R=301,L]
RewriteRule ^(.*)/index\.(.*)$ /$1/ [R=301,L]
or to base it from the initial URL request only (to avoid conflicts with other rewrite rules):
RewriteEngine On
RewriteCond %{THE_REQUEST} /index\.(.*) [NC]
RewriteRule ^(.*?)index\.(.*)$ /$1 [R=301,L]
I would like to hide the index.php page and just show the domain.
Is this possible with .htaccess?
RewriteRule ^index\.php/?$ / [L,R=301,NC]
Also tried:
RewriteEngine On
RewriteBase /
RewriteCond %{THE_REQUEST} ^[A-Z]{3,9} /index.php HTTP/
RewriteRule ^index.php$ http://example.com/ [R=301,L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
index.php still shows
Try, It works for me! Make sure your have AllowOverride All set in httpd.conf
RewriteEngine On
RewriteCond %{REQUEST_URI} index\.php
RewriteRule ^(.*)index\.php$ /$1/ [R=301,L]
There is a regex issue in your rules, I have modified your rules and it works for me:
RewriteEngine On
RewriteBase /
RewriteCond %{THE_REQUEST} index\.php
RewriteRule ^index\.php$ http://example\.com/ [R=301,L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index\.php [L]
RewriteRule ^(.*)index\.(html|php)$ http://%{HTTP_HOST}/$1 [R=301,L]
You can rewrite '/index.php' through .htaccess like this:
# Remove /index.php from all urls
RewriteRule ^(.+)/index\.php$ /$1 [R=302,L]
I found this solution to redirect urls from www.domain.com/example.php to www.domain.com/example successfully but I cannot do the same when are few subdirs present, like with: domain.com/dir1/di2/dir3/example.php to domain.com/dir1/di2/dir3/example
How should this rule be modded in order to make the previous redirection work?
RewriteRule (.*).php$ /$1 [R=301,L]
RewriteRule (.*).html$ /$1 [R=301,L]
This is my .htaccess
ErrorDocument 404 /misc/404.html
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}\.html -f
RewriteRule ^(.*)$ $1.html
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}\.php -f
RewriteRule ^(.*)$ $1.php
RewriteRule (.*).php$ /$1 [R=301,L]
RewriteRule (.*).html$ /$1 [R=301,L]
# Forces a trailing slash to be added
#RewriteCond %{REQUEST_FILENAME} !-f
#RewriteCond %{REQUEST_FILENAME} !-d
#RewriteCond %{REQUEST_URI} !(\.[a-zA-Z0-9]{1,5}|/)$
#RewriteRule (.*)$ /$1/ [R=301,L]
Thank you!
http://demo.domain.com/en/index.php is taking me to http://demo.domain.com/index and it should take me to http://demo.domain.com/en/index
the .htaccess is in /en/ directory
You need to add a:
RewriteBase /en/
right below RewriteEngine on.
You also may need to add a /en/ to the redirect rules and conditions:
RewriteRule (.*).php$ /$1 [R=301,L]
RewriteRule (.*).html$ /$1 [R=301,L]
Needs to be:
RewriteCond %{ENV:REDIRECT_STATUS} !200
RewriteRule (.*).php$ /en/$1 [R=301,L]
RewriteCond %{ENV:REDIRECT_STATUS} !200
RewriteRule (.*).html$ /en/$1 [R=301,L]
I am stuck trying to write a rewrite rule for my htaccess file which should forward from for example www.example.com/en to www.example.com/en/
I tried: RewriteRule ^en/?$ en [L]
but nothing happens. Does someone have an idea how to accomplish this?
You can use following rules in your .htaccess file:
Options +FollowSymLinks -MultiViews
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(?![^/]*/).*$ %{REQUEST_URI}/ [L,R]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^([^/]*)/$ index.php?lang=$1 [QSA,L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^([^/]*)/([^/]*)/?$ index.php?action=$2&lang=$1 [QSA,L]
This will:
externally redirect: /en to /en/ and internally redirect this to /index.php?lang=en
internall redirect: /fr/login to /index.php?action=login&lang=fr
Additionally: As per your comment you will need this rule to add www in domain:
RewriteCond %{HTTP_HOST} ^example\.com$ [NC]
RewriteRule ^ http://www.%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
Use RedirectMatch:
RedirectMatch Permanent ^/en$ /en/