Redirect from index.html to root - .htaccess

I have entered this code in .htaccess and it gives me the error "bad flag delimiters" and the website is unreacheable after this code (it give error 500 internal server error).
Anybody knows what is wrong with this code?
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} -f
RewriteCond %{REQUEST_URI} ^(.+)\.html$
RewriteRule (.+)\.html$ https://www.kamagra-uzitek.com/$1 [R=301,L]
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}.html -f
RewriteCond %{REQUEST_URI} !^(.+)\.html $
RewriteRule ^(.+)$ /$1\.html [END]
Thank you for your help!

Related

multiple rules of URL rewriting

RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}\.html -f
RewriteRule ^(.*)$ $1.html[L,QSA]
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}\.php -f
RewriteRule ^(.*)$ $1.php
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^([a-zA-Z0-9_-]+)$ /profile.php?name=$1
RewriteRule ^([a-zA-Z0-9_-]+)/$ /profile.php?name=$1
This is currently .htaccess of my website. The rewriting supposes to have two functions, makes the internal url example/profile.php/name=xyz into example/xyz as external url, and also removes the extensions of html files.
But the extension removing is not working, and such as for a file named xyz.html, it gets 404 and
example.com/xyz/?name=xyz
At the address bar. I think there is some conflicts between two rules.
RewriteCond is only applicable to very next RewriteRule hence your last rule is running without any RewriteCond. Also you need to use [L] (Last) flag in all of your rules.
Use this code:
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}\.html -f
RewriteRule ^(.*)$ /$1.html [L]
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}\.php -f
RewriteRule ^(.*)$ /$1.php [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^([\w-]+)/?$ /profile.php?name=$1 [L]

.htaccess - Clean URL, 500 Internal Server Error

I've got this as my .htaccess:
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}\.php -f
RewriteRule ^(.*)$ $1.php
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}\.html -f
RewriteRule ^(.*)$ $1.html
# Where it's all about
RewriteRule ^users/([a-zA-Z0-9]+)$ users.php?user=$1
RewriteRule ^users/([a-zA-Z0-9]+)/$ users.php?user=$1
RewriteEngine On
RewriteCond %{HTTP_HOST} ^www.daltonempire.nl [nocase]
RewriteRule ^(.*)
http://daltonempire.nl/$1 [last,redirect=301]
I tried to make clean urls, redirecting daltonempire.nl/users/Me to daltonempire.nl/users.php?user=Me.
However, I failed miserably. My website now constantly returns a 500 Internal Server Error.
(I possibly somehow created a redirection loop?)
What did I do wrong? (And what do I have to do to fix it?)
Believe you have an extra newline in last rule. Also make sure to use L (Last) flag in all of your rules.
RewriteEngine on
# Where it's all about
RewriteRule ^users/([a-zA-Z0-9]+)/?$ users.php?user=$1 [L,QSA]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}\.php -f
RewriteRule ^(.+?)/?$ $1.php [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}\.html -f
RewriteRule ^(.+?)/?$ $1.html [L]
RewriteCond %{HTTP_HOST} ^www\.(daltonempire\.nl)$ [NC]
RewriteRule ^ http://%1%{REQUEST_URI} [L,R=301,NE]

Htaccess :Rewrite rule issue

I've following code in a .htaccess file. The file is in a subfolder, lets say /content/.
RewriteCond %{REQUEST_FILENAME} -s [OR]
RewriteCond %{REQUEST_FILENAME} -l [OR]
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^([^/]+)(/([^/]+))?(/(edit)+)(/([^/]+))?/?$ edit.php?category=$1&slug=$3&edit=$5&password=$7 [L]
RewriteRule ^([^/]+)(/([^/]+)?/?)$ content.php?category=$1&slug=$3 [L]
I'm expecting above code will rewrite,
mydomain.com/content/text1/text2/edit/my_password to mydomain.com/content/edit.php?category=text1&slug=text2&password=my_password
mydomain.com/content/text1/text2 to mydomain.com/content/content.php?category=text1&slug=text2
mydomain.com/content/text1 to mydomain.com/content/content.php?category=text1
mydomain.com/content/ to mydomain.com/content/content.php
The code rewrites above correctly, But it breaks the asset urls.
e.g. It rewrites http://mydomain.com/content/js/tms.js to something else, it is same for the css files. My assets folders are /img, /css, /js.
If i commented RewriteRule ^([^/]+)(/([^/]+))?(/(edit)+)(/([^/]+))?/?$ edit.php?category=$1&slug=$3&edit=$5&password=$7 [L] line it works for the assets
Any ideas how to fix this?
The condition RewriteCond %{REQUEST_FILENAME} -d means that "the request is for an existing directory". If you add a ! in front of the -d it changes it to "the request is not for an existing directory".
Try:
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^([^/]+)/([^/]+)(/edit)+/([^/]+?)/?$ edit.php?category=$1&slug=$2&password=$4 [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^([^/]+)/([^/]+?)/?$ content.php?category=$1&slug=$2 [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^([^/]+?)/?$ content.php?category=$1 [L]

Trying to block ZmEu and Ezooms using htaccess mod-rewrite results in error 310 ERR_TOO_MANY_REDIRECTS

I'm trying to block the ZmEu and Ezooms abuse I've been getting. I tried following what was discussed in this link: http://www.philriesch.com/articles/2010/07/getting-a-little-sick-of-zmeu/ but my attempt results in Error 310, too many redirects. Any idea what's causing this loop?
My htaccess code is below. I temporarily set one of the HTTP_USER_AGENT values as Chrome to test it.
RewriteEngine on
RewriteCond %{REQUEST_URI} !^/my_base/special/ip-flagged
RewriteCond %{HTTP_USER_AGENT} (.*)Chrome(.*)|(.*)ZmEu(.*)
RewriteRule .* /my_base/special/ip-flagged [R=301,L]
RewriteBase /my_base
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule .* index.php/$1 [PT,L]
Thanks
I figured it out. Adding the lines,
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
to the first RewriteRule stopped the loop. So now the following code always redirects to the "ip-flagged" page whenever the browser used is Chrome:
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI} !^/my_base/special/ip-flagged
RewriteCond %{HTTP_USER_AGENT} (.*)Chrome(.*)
RewriteRule .* /my_base/special/ip-flagged [R=301,L]
RewriteBase /my_base
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule .* index.php/$1 [PT,L]

“Internal Server Error ” on invalid pages

Some lines of my htaccess file will be look like as follows
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI} !\.css$
RewriteCond %{REQUEST_URI} !\.js$
RewriteCond %{REQUEST_URI} !\.images$
RewriteCond %{REQUEST_URI} ^/(.*)$
RewriteCond %{REQUEST_URI} !(\.jpg|\.gif|\.png)$ [NC]
RewriteRule ^(.*)$ user/$1 [L,QSA]
But when I go for a invalid url, so for mydomain.com/blablabla ,it's giving Internal Server Error. Is anything wrong with my .htaccess
Try adding these conditions right after RewriteCond %{REQUEST_URI} ^/(.*)$
RewriteCond %{DOCUMENT_ROOT}/user/%1 -f [OR]
RewriteCond %{DOCUMENT_ROOT}/user/%1 -d
This checks if the rewritten URI would exist, if it doesn't, it won't do the rewrite, which is causing an internal loop if the URI doesn't exist.

Resources