my htaccess rules works fine in Apache but i had to change to LiteSpeed and my page doesnt work properly (eg if i type url like http://domain.com/article/some-article or http://domain.com/article/tags/some-tag). Maybe somebody coped with similar problem? In server logs i get : Maximum number of redirect reached.
My htaccess:
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)/$ /$1 [L,R=301]
# browser requests PHP
RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /([^\ ]+)\.php
RewriteRule ^/?(.*)\.php$ /$1 [L,R=301]
# check to see if the request is for a PHP file:
RewriteCond %{REQUEST_FILENAME}\.php -f
RewriteRule ^/?(.*)$ /$1.php [L]
RewriteCond %{REQUEST_URI} .article.php/tags/([^/]+)$ [NC]
RewriteRule ^(.*)$ article.php?tag=%1 [L,NC,QSA]
RewriteCond %{REQUEST_URI} .article.php/([^/]+)$ [NC]
RewriteRule ^(.*)$ article.php?art=%1 [L,NC,QSA]
RewriteCond %{REQUEST_URI} .article.php/(.+)$ [NC]
RewriteRule ^(.*)$ http://domain.com/article/$1 [L,R=301]
I will be grateful for your help
I show you how I coped with the problem - I had to change rules and order - I think there was some loop redirection:
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteCond %{HTTP_HOST} !^www\.
RewriteRule ^(.*)$ http://www.%{HTTP_HOST}/$1 [R=301,L,NC]
RewriteCond %{REQUEST_URI} .articles/tags/([^/]+)$ [NC]
RewriteRule ^(.*)$ articles.php?tag=%1 [L,NC,QSA]
RewriteCond %{REQUEST_URI} .articles/([^/]+)$ [NC]
RewriteRule ^(.*)$ articles.php?article=%1 [L,NC,QSA]
RewriteCond %{REQUEST_URI} .articles.php/tags/([^/]+)$ [NC]
RewriteRule ^(.*)$ articles/tags/%1 [L,R=301]
RewriteCond %{REQUEST_URI} .articles.php/([^/]+)$ [NC]
RewriteRule ^(.*)$ articles/%1 [L,R=301]
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)/$ /$1 [L,R=301]
# browser requests PHP
RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /([^\ ]+)\.php
RewriteRule ^/?(.*)\.php$ /$1 [L,R=301]
# check to see if the request is for a PHP file:
RewriteCond %{REQUEST_FILENAME}\.php -f
RewriteRule ^/?(.*)$ /$1.php [L]
#301 redirect error page (instead of 302 - for SEOD reason)
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule . /page-not-found [L,R=301]
</IfModule>
Related
I've read through the other posts pertaining to this topic and still haven't found my solution.
My .htaccess is as follows:
RewriteEngine On
Options +FollowSymLinks
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)/$ /$1 [L,R]
ErrorDocument 404 https://website.com/page/404
# browser requests PHP
RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /([^\ ]+)\.php
RewriteRule ^/?(.*)\.php$ /$1 [L,R=301]
RewriteCond %{THE_REQUEST} ^.*/index
RewriteRule ^(.*)index /$1 [R=301,L]
# check to see if the request is for a PHP file:
RewriteCond %{REQUEST_FILENAME}\.php -f
RewriteRule ^/?(.*)$ /$1.php [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule .*[^/]$ %{REQUEST_URI}/ [L,R]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{DOCUMENT_ROOT}/$1\.php -f [NC]
RewriteRule ^profile/([0-9a-zA-z_-]+) profile.php?username=$1 [L,QSA,NC]
Whenever I navigate to https://website.com/page/profile/name/ I receive a 500 internal server error.
The other conditions seem to be working properly however this one in particular is not.
This can not work :
RewriteRule ^profile/([0-9a-zA-z_-]+) profile.php?username=$1 [L,QSA,NC]
you must define the variable with this : (.*)
RewriteEngine on
RewriteBase "/"
RewriteCond %{HTTP_Host} "!^$" [NC]
RewriteRule "^profile/(.*).php$" "profile.php?username=$1" [NC,L,QSA]
after this you can check the regex.
I am trying to create a simple CMS.I need the .htaccess to rewrite links pointing to /index.php to just /while all other /files.php to /files.
Currently, I am using something like
RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /([^\ ]+)\.php
RewriteRule ^/?(.*)\.php$ /$1 [L,R=301]
RewriteCond %{REQUEST_FILENAME}\.php -f
RewriteRule ^/?(.*)$ /$1.php [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
This is rewriting <a href='layout/header.php'> to /header in URL panel, which is good. But navigating back to /index.php will result in /index.php, which is bad.
What am I missing here?
This solved my problem
RewriteEngine On
RewriteBase /
RewriteCond %{THE_REQUEST} ^GET.*index\.php [NC]
RewriteRule (.*?)index\.php/*(.*) /$1$2 [R=301,NE,L]
RewriteCond %{THE_REQUEST} ^GET.*index [NC]
RewriteRule (.*?)index\.php/*(.*) /$1$2 [R=301,NE,L]
RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /([^\ ]+)\.php
RewriteRule ^/?(.*)\.php$ /$1 [L,R=301]
Hello all i am having a website where i have htaccess file the code inside the file seems like
ErrorDocument 404 /error404.php
ErrorDocument 403 /error404.php
Options -Indexes
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_METHOD} POST [NC]
RewriteRule ^ - [L]
RewriteCond %{HTTP_REFERER} !^http://(www\.)?domain.*$ [NC]
RewriteRule \.(gif|jpg|jpeg)$ http://www.domain.com [L]
RewriteCond %{HTTP_HOST} !^www\.
RewriteRule ^(.*)$ http://www.%{HTTP_HOST}/$1 [R=301,L]
RewriteCond %{THE_REQUEST} \s/+(page1)\.php\?eid=(78)[&\s] [NC]
RewriteRule ^ /%1/%2? [R=301,L]
RewriteRule ^(page1)/(\d+)$ /$1.php?eid=$2 [L,QSA,NC]
RewriteCond %{THE_REQUEST} \s/+page2\.php\?url=([^\s&]+) [NC]
RewriteRule ^ /%1? [R=301,L]
RewriteCond %{THE_REQUEST} \s/+(.+?)\.php[\s?] [NC]
RewriteRule ^ /%1 [R=302,L,NE]
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{DOCUMENT_ROOT}/$1\.php -f [NC]
RewriteRule ^(.+?)/?$ /$1.php [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.+)$ /page2.php?url=$1 [L,QSA]
The file successfully redirects the page2.php?url=xyz to page2/xyz but it directs the page1.php?eid=3 to page1?eid=3 besides this i also needs to direct the page3.php?did=3 to page3/3
I need the page2.php?eid=3 to be directed to page2/3
and page3.php?did=4 to page3/4
page1 is directed fine.
Can any one help me actually i am not so good in htaccess but i have tried to manipulate the htacces file but no help.
Thanks
I need your help.
I have a problem to rewrite a dynamic url after extension removed, I've rewritten this url but not works:
.htaccess like this:
<IfModule mod_rewrite.c>
Options -Multiviews
Options +FollowSymLinks
RewriteEngine On
RewriteBase /
#add www 1
RewriteCond %{HTTP_HOST} !^www\.mondomain\.com$ [NC]
RewriteRule ^(.*)$ http://www.mondoamin.com/$1 [R=301,L]
#remove .php extension 2
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)/$ /$1 [R=301,L]
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}\.php -f
RewriteRule ^(.*)$ $1.php [L]
# Removes index.php from ExpressionEngine URLs 3
RewriteCond %{THE_REQUEST} ^GET.*index\.php [NC]
RewriteCond %{REQUEST_URI} !/system/.* [NC]
RewriteRule (.*?)index\.php/*(.*) /$1$2 [R=301,NE,L]
# Directs all EE web requests through the site index file
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-l
RewriteRule ^(.*)$ /index.php/$1 [L]
#rewrite url 4
RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /article\.php\?id_ article =([^&\ ]+)([^\ ]*)
RewriteRule ^/article/%1?%2 [L,R=301]
RewriteCond %{THE_REQUEST} ^[A-Z]+\ /([^/]+/)*[^.#?\ ]+\.php([#?][^\ ]*)?\ HTTP/
RewriteRule ^(([^/]+/)*[^.]+)\.php $1 [R=301,L]
</IfModule>
results:
1+2+3 works fine but 4 not works
Thanks in advance
Try reordering the rules and keep 301 rules before internal rewrites:
Options -Multiviews
Options +FollowSymLinks
RewriteEngine On
RewriteBase /
#add www 1
RewriteCond %{HTTP_HOST} !^www\.mondomain\.com$ [NC]
RewriteRule ^(.*)$ http://www.mondoamin.com/$1 [R=301,L]
#rewrite url 4
RewriteCond %{THE_REQUEST} /article\.php\?id_article=([^&\ ]+)([^\ ]*)
RewriteRule ^ /article/%1?%2 [L,R=301]
RewriteRule ^article/([^/]+)/?$ /article.php?id_article=$1 [L,QSA]
RewriteCond %{THE_REQUEST} ^[A-Z]+\ /([^/]+/)*[^.#?\ ]+\.php([#?][^\ ]*)?\ HTTP/
RewriteRule ^(([^/]+/)*[^.]+)\.php $1 [R=301,L]
#remove .php extension 2
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)/$ /$1 [R=301,L]
# Removes index.php from ExpressionEngine URLs 3
RewriteCond %{THE_REQUEST} ^GET.*index\.php [NC]
RewriteCond %{REQUEST_URI} !/system/.* [NC]
RewriteRule (.*?)index\.php/*(.*) /$1$2 [R=301,NE,L]
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}\.php -f
RewriteRule ^(.*)$ $1.php [L]
# Directs all EE web requests through the site index file
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-l
RewriteRule ^(.*)$ /index.php/$1 [L]
this is the my last .htaccess code:
Options -Multiviews
Options +FollowSymLinks
RewriteEngine On
RewriteBase /
add www
RewriteCond %{HTTP_HOST} !^www.mondomain.fr$ [NC]
RewriteRule ^(.*)$ http://www.mondomaine.fr/$1 [R=301,L]
rewrite dynamic url
RewriteCond %{THE_REQUEST} /article.php\?id_article=([^&\ ]+)([^\ ]*)
RewriteRule ^ /article/%1?%2 [L,R=301]
RewriteRule ^ article/([^/]+)/?$ /article.php?id_article=$1 [L,QSA]
RewriteCond %{THE_REQUEST} ^[A-Z]+\ /([^/]+/)[^.#?\ ]+.php([#?][^\ ])?\ HTTP/
RewriteRule ^(([^/]+/)*[^.]+).php $1 [R=301,L]
remove .php extension
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)/$ /$1 [R=301,L]
Removes index.php from ExpressionEngine URLs
RewriteCond %{THE_REQUEST} ^GET.*index.php [NC]
RewriteCond %{REQUEST_URI} !/system/.* [NC]
RewriteRule (.?)index.php/(.*) /$1$2 [R=301,NE,L]
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}.php -f
RewriteRule ^(.*)$ $1.php [L]
Directs all EE web requests through the site index file
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-l
RewriteRule ^(.*)$ /index.php/$1 [L]
How to redirect mydomainname.com/index.php to mydomainname.com
Currently I use following codes also.
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{HTTP_HOST} !^mydomianname\.com
RewriteRule (.*) http://mydomianname.com/$1 [R=301,L]
RewriteCond %{THE_REQUEST} ^[A-Z]{3,}\s/+index\.php\?p=([^\s&]+) [NC]
RewriteRule ^ /%1? [R=301,L]
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)$ index.php?p=$1 [QSA,L]
</IfModule>
This should be your complete .htaccess:
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{HTTP_HOST} !^mydomianname\.com
RewriteRule (.*) http://mydomianname.com/$1 [R=301,L]
RewriteCond %{THE_REQUEST} ^[A-Z]{3,}\s/+index\.php\?p=([^\s&]+) [NC]
RewriteRule ^ /%1? [R=301,L]
# remove index.php
RewriteCond %{THE_REQUEST} /index\.php [NC]
RewriteRule ^(.*?)index\.php$ /$1 [L,R=301,NC,NE]
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)$ index.php?p=$1 [QSA,L]
</IfModule>
This example only works for http, but should roughly do the trick.
# Redirect requests with index.php to the corresponding request
# without the index.php
RewriteRule ^index.php(.*) http://mydomianname.com$1 [R=301,L]