.htaccess how to use RedirectMatch - .htaccess

Since I changed the structure of my website, some of the links became broken.
What rule should I write in .htaccess to fix the problem.
before it was like this
/news/194-kozyrnyj-vecher-premier-ligi.html
and now it looks like this
/news/2-news/194-kozyrnyj-vecher-premier-ligi.html
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI} !^/index.php
RewriteCond %{REQUEST_URI} (/|\.php|\.html|\.htm|\.feed|\.pdf|\.raw|/[^.]*)$ [NC]
RewriteRule (.*) index.php
RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization},L]
RewriteCond %{REQUEST_URI} !^/news/2-news/(.*)
RewriteRule ^news/(.*)$ /news/2-news/$1 [R=permanent,L]

should be:
RewriteCond %{REQUEST_URI} !^/news/2-news/(.*)
RewriteRule ^news/(.*)$ /news/2-news/$1 [R=permanent,L]
in your .htaccess file

Related

htaccess redirects affect administrator page on Joomla

I have a task - all somestuff.html/ pages with trailing slash must redirect to somestuff.html and all other pages without a trailing slash must redirect to add a trailing slash (e.g. /mypage must redirect to /mypage/). I have accomplished the task but now /administrator/ page returns 404 page. I tried to exclude the /administrator/ page but its not working:
DirectoryIndex index.php
RewriteEngine on
RewriteBase /
RewriteCond %{HTTP_HOST} ^www\.(.*) [NC]
RewriteRule ^(.*)$ http://%1/$1 [R=301,L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
#this part breaks the admin panel entry
RewriteRule ^([^.]+).html/ http://somedomain.com/$1\.html [R=301,L]
RewriteCond %{REQUEST_URI} !\.(php|html?|jpg|gif)$
#trying to exclude administrator page
RewriteCond %{REQUEST_URI} !^/administrator/
RewriteRule ^(.*)([^/])$ http://%{HTTP_HOST}/$1$2/ [L,R=301]
#end of part that breaks the admin panel entry
RewriteCond %{REQUEST_URI} !^/index.php
RewriteCond %{REQUEST_URI} (/|\.php|\.html|\.htm|\.feed|\.pdf|\.raw|/[^.]*)$ [NC]
RewriteRule (.*) index.php
RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization},L]
Can anyone tell me what I am doing wrong or maybe offer some different solution to acocmplish the redirecting. Thanks.
Found a solution:
DirectoryIndex index.php
RewriteEngine on
RewriteBase /
RewriteCond %{HTTP_HOST} ^www\.(.*) [NC]
RewriteRule ^(.*)$ http://%1/$1 [R=301,L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{HTTP_HOST} ^www\.(.*) [NC]
RewriteRule ^(.*)$ http://%1/$1 [R=301,L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^([^.]+).html/ http://logosstudy.ru/$1\.html [R=301,L]
RewriteCond %{REQUEST_URI} !^/administrator/
RewriteCond %{REQUEST_URI} !\.(php|html?|jpg|gif)$
RewriteRule ^(.*)([^/])$ http://%{HTTP_HOST}/$1$2/ [L,R=301]
RewriteCond %{REQUEST_URI} !^/administrator/
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI} !^/index.php
RewriteCond %{REQUEST_URI} (/|\.php|\.html|\.htm|\.feed|\.pdf|\.raw|/[^.]*)$ [NC]
RewriteRule (.*) index.php
RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization},L]

Create .htaccess Wildcard with Subdomains

I'm trying to implement a solution using .htaccess and wildcard subdomains so that
http://example.com.domain.com is mapped to http://domain.com/www/example.com
. My rules look something like:
RewriteCond %{HTTP_HOST} !^www\.domain\.com$ [NC]
RewriteCond %{HTTP_HOST} !^domain\.com$ [NC]
RewriteCond %{HTTP_HOST} ^(www.)?([a-z0-9-\.]+)\.domain\.com$ [NC]
RewriteRule !^www/ www/%2%{REQUEST_URI} [PT,L]
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . index.php [L]
Try changing the second rule to:
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule !^www/ index.php [L]

remove index.php from url only for the client

I know there are some questions like this out there but the solutions are not helpful for me.
I´m using htaccess to redirect to the index.php if the request file isn´t defined (code above).
I´d like to add a code-line that if the user requests for example:
http://www.example.com/test/index.php
he will redirect to
http://www.example.com/test/
but internal it will redirect to the index.php.
Is there a way to extend my code so that it works like I want it to?
# Add Slash
RewriteCond %{REQUEST_URI} !(/$|\.)
RewriteRule (.*) %{REQUEST_URI}/ [R=301,L]
# Redirect to index.php if the following sites were not match
RewriteBase /
RewriteCond %{REQUEST_URI} \.(php|sql|tgz|gz|txt|ttf|TTF|log|txt|ini|html|xml|xhtml|htm)$
RewriteCond %{REQUEST_URI} !^/index.php$
RewriteCond %{REQUEST_URI} !^/phpinfo.php$
RewriteCond %{REQUEST_URI} !^/out.php$
RewriteCond %{REQUEST_URI} !^/sitemap[^0-9]*\.xml$
RewriteCond %{REQUEST_URI} !^/robots.txt$
RewriteRule ^(.*)$ /index.php?dir=$1 [QSA,L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_URI} !^/$
RewriteRule ^(.*)$ /index.php?dir=$1 [QSA,L]
Complete code:
DirectoryIndex index.php index.html
Options +FollowSymLinks -MultiViews
# Turn mod_rewrite on
RewriteEngine On
RewriteBase /
# Take off index.php
RewriteCond %{REQUEST_URI} ^(.*/)index\.php$ [NC]
RewriteRule ^ http://%{HTTP_HOST}%1 [R=301,L]
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI} \.(php|sql|tgz|gz|txt|ttf|TTF|log|txt|ini|html|xml|xhtml|htm)$
RewriteCond %{REQUEST_URI} !^/((index|phpinfo|out)\.php|robots\.txt|sitemap[^0-9]*\.xml)$
RewriteRule ^(.*)$ /index.php?dir=$1 [QSA,L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.+)$ /index.php?dir=$1 [QSA,L]
# Add Slash for non-files
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule [^/]$ %{REQUEST_URI}/ [R=301,L]

.htaccess single variable url rewrite

I am trying to redirect http://test.pearlsquirrel.com/explore_all?u=hiphop to http://test.pearlsquirrel.com/explore_all/hiphop using htaccess. However, It keeps redirecting here: http://test.pearlsquirrel.com/explore_all/?u=site_error.php. I have looked all over Stackoverflow for the answer but I just can't seem to find it. I would really appreciate some help in fixing this problem, thanks!
Here is my .htaccess file
Options +FollowSymlinks
RewriteEngine On
RewriteBase /
RewriteCond %{HTTP_HOST} ^www\.pearlsquirrel.com$ [NC]
RewriteRule ^(.*)$ http://pearlsquirrel.com/$1 [L,R=301]
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}\.php -f
RewriteRule ^([^/]+)/$ $1.php
RewriteCond %{REQUEST_URI} !(\.[a-zA-Z0-9]{1,5}|/)$
RewriteRule (.*)$ /$1/ [R=301,L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^([^/]+) explore_all?u=$1 [L]
You may try this:
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{QUERY_STRING} [^=]+=([^=]+)
RewriteRule .* /%1? [L]
Will map this:
http://test.pearlsquirrel.com/explore_all?u=hiphop
To this:
http://test.pearlsquirrel.com/explore_all/hiphop
Replace the corresponding code in your .htaccess file with this one.
I have not checked the rules in your .htaccess file.
OPTION
Now, if it is the other way around, which I think it is, and the idea is to map this incoming URL:
http://test.pearlsquirrel.com/explore_all/hiphop
To this resource:
http://test.pearlsquirrel.com/explore_all?u=hiphop
Replace the above rule set with this one:
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI} .*/([^/]+)/?
RewriteRule .* http://test.pearlsquirrel.com/explore_all?u=%1 [L]

htaccess subdomain ssl wildcard not opening file

Ok So i have come across a problem with my htaccess and how to get it to work.
I have just purchased a ssl wildcard for my primary and sub domains.
I am with bluehost and they suggest adding this:
RewriteEngine On
RewriteCond %{HTTP_HOST} ^subdomain.example.com$
RewriteCond %{REQUEST_URI} !^/subfolder/
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ /subdomain/$1
RewriteCond %{HTTP_HOST} ^subdomain.example.com$
RewriteRule ^(/)?$ subfolder/index.php [L]
At the moment all i have is this...
RewriteEngine On
RewriteCond %{HTTP_HOST} ^domain\.com
RewriteRule ^(.*)$ https://www.domain.com/$1 [L]
RewriteCond %{HTTP_HOST} ^sub.domain.com
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule . sub_folder/index.php [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule . /index.php [L]
and that works however, i cannot get it so that when i open the file, it just opens the file with no redirects...
So If i open sub.domain.com/file/fil1.js it will open the index.php which is what i do not want...
but if i do /browse or something like that it works...
Ok after much mucking around and playing around it was the file request which wasnt including the subdomain folder, which was causing it to not find the file location. So I managed to do a manual check for the file, and this is what i got. This seems to do exactly what i want. Im not sure if there is a more efficient way, but this is what it got.
#-------------------SUB.DOMAIN.COM---------------------
RewriteCond %{HTTP_HOST} ^sub.domain.com
RewriteCond %{DOCUMENT_ROOT}/sub_folder%{REQUEST_URI} -f
RewriteRule . %{DOCUMENT_ROOT}/sub_folder%{REQUEST_URI} [L]
RewriteCond %{HTTP_HOST} ^sub.domain.com
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule . sub_folder/index.php [L]
#--------------------------------------------------------------
instead of
RewriteCond %{HTTP_HOST} ^sub.domain.com
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule . sub_folder/index.php [L]
You need to change your second rule so that it only gets applied when the request is ^(/)?$, then you need to duplicate what bluehost tells you to do. Essentially, replace:
RewriteCond %{HTTP_HOST} ^sub.domain.com
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule . sub_folder/index.php [L]
With what they tell you to use:
RewriteCond %{HTTP_HOST} ^sub.domain.com$
RewriteCond %{REQUEST_URI} !^/subfolder/
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ /subdomain/$1 [L]
RewriteCond %{HTTP_HOST} ^sub.domain.com
RewriteRule ^/?$ /sub_folder/index.php [L]

Resources