index.php to root in htaccess - .htaccess

What does this mean? I am trying to remove index.php from the URL and point to root. For example,
https://www.example.com/index.php redirect to https://www.example.com/
The below solution works absolutely fine. However, I am unclear about the HTTP/ used in RewriteCond line. What does it do? Can someone please explain?
RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /index\.php\ HTTP/
RewriteRule ^index\.php$ https://www.aviatrix.com/$1 [R=301,L]

Related

htaccess multiple urls to one page redirect not working

I have a bunch of url's like https://example.com/index.php?articles_id=XX, where XX is some number. I want to
redirect all of them to https://example.com/maps.php (ignoring the parameters) but none of the redirect code I use works. When visiting the
original url, the browser just cycles until it finally times out. The second url is to a working page.
I first tried:
RewriteRule ^articles_id=(.*)$ /maps.php [L,R=301]
then
RewriteRule ^https://example.com/index.php?articles_id=(.*)$ /maps.php [L,R=301]
then
RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /index\.php?articles_id=\ HTTP/
RewriteRule ^index\.php?articles_id=$ https://example.com/maps.php [R=301,L]
and finally
RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /index\.php?articles_id=\ HTTP/
RewriteRule ^(.*)$ ./maps.php [R=301,L]
There is other redirect code in the file that is working, like this one:
RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /index\.php\ HTTP/
RewriteRule ^index\.php$ https://example.com/ [R=301,L]
Can someone please point out the reason why the redirects are not working?
This turned out to be code in the files that was preventing the redirect.

301 redirection is not working in html website

I used this below code to redirect my website (www.earabictoenglish.com) but it is not working please help me to redirect it! my website developer is confused! Please rewrite and help me...i dont know what is the error ???
RewriteEngine On
RewriteBase /
RewriteCond %{HTTP_HOST} ^earabictoenglish.com [NC]
RewriteRule ^(.*)$ http://www.earabictoenglish.com/$1 [L,R=301]
RewriteEngine on
RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /index\.pages\ HTTP/
RewriteRule ^index\.pages$ http://www.earabictoenglish.com/ [R=301,L]

Rewrite Rule to Redirect index.php to www

I have come across three different options for doing a 301 redirect from index.php to root.
Option 1: Redirect index.php to www
RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /index\.php
RewriteRule ^index\.php$ / [L,R=301]
Option 2: Redirect index.php to www
RewriteCond %{THE_REQUEST} ^.*/index.php
RewriteRule ^(.*)index.php$ /$1 [L,R=301]
Option 3: Redirect index.php to www
RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /index\.php [NC]
RewriteRule ^index\.php$ https://www.domain.co.uk/$1 [L,R=301]
Can anyone please help me understand the difference in the above three substitute options? In rewrite rule, what will be the impact of having:
/
/$1
https://www.domain.co.uk/$1
The first option redirects index.php (from root level only) to /.
Example: http://www.domain.com/index.php becomes http://www.domain.com/.
The second option redirects index.php to its root folder.
Example: http://www.domain.com/x/z/index.php becomes http://www.domain.com/x/z/.
The third option is equivalent to first option even if it has syntax errors and won't work ($1 is null since no group is captured in rule).
Conclusion (redirect index.php from root level to / root)
If i had to do it myself, the code would look like this
RewriteCond %{THE_REQUEST} \s/index\.php\s [NC]
RewriteRule . / [R=301,L]

Duplicate URLs and solution in htaccess

after years I discovered a bug in duplication URLs that I try to fix (author is gone) despite htaccess rule I thought should force it.
Issue:
I have the same content under 2 URLS, ex:
http://www.wrock.pl/news-23069/Depeche_Mode_Party_w_klubie_Liverpool_/
www.wrock.pl/index.php?s=news&d=23069&nazwa=Depeche_Mode_Party_w_klubie_Liverpool_
or shorter www.wrock.pl/index.php?s=news&d=23069
Another example are menu pages:
http://www.wrock.pl/koncerty/
www.wrock.pl/index.php?s=koncerty
I thought the "index.php" version should be hidden or redirected to friendly URL version, meanwhile both show with 200/OK
Index.php itself gets redirected OK: www.wrock.pl/index.php
Aim:
be able to show only friendly URl version (redirect the index.php version).
Google stopped indexing them so it may be an issue (one of many reasons).
Here is my htaccess responsible for presented examples:
RewriteEngine On
RewriteCond %{HTTP_HOST} ^wrock.pl(.*) [NC]
RewriteRule ^(.*)$ http://www.wrock.pl/$1 [R=301,L]
# REDIRECT index.php to /
RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /([^/]+/)*index\.php\ HTTP/
RewriteRule ^(([^/]+/)*)index\.php$ http://www.wrock.pl/$1 [R=301,L]
#NEWS
RewriteRule ^news-([0-9]+)/([^-]+)/$ index.php?s=news&d=$1&nazwa=$2 [L,NC]
RewriteRule ^news/([0-9]+)/$ index.php?s=news&strona=$1 [L,NC]
#KONCERTY
RewriteRule ^koncerty/$ index.php?s=koncerty [L,NC]
I dont know if current redirections should be changes or should I enter something like:
#RewriteRule ^index.php?s=news&d=([0-9]+)&nazwa=([^-]+)$ http://www.wrock.pl/news-$1/$2/ [L,NC]
which doesn't work of course.
Thank You very much for any suggestions.
Above your #NEWS items, you need to add these rules:
RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /index\.php\?s=news&d=([0-9]+)&nazwa=([^-&\ ]+)($|\ )
RewriteRule ^ /news-%1/%2/ [L,R=301]
RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /index\.php\?s=news&strona=([0-9]+)($|\ )
RewriteRule ^ /news/%1/ [L,R=301]
RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /index\.php\?s=koncerty
RewriteRule ^ /koncerty/ [L,R=301]
And in order to handle the "shorter www.wrock.pl/index.php?s=news&d=23069":
RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /index\.php\?s=news&d=([0-9]+)($|\ )
RewriteRule ^ /news-%1/ [L,R=301]
RewriteRule ^news-([0-9]+)/$ index.php?s=news&d=$1 [L]

How do i redirect user if user enter the URL with /index.php to without having /index.php in the url

I am facing a little problem with URL's redirection in my site. This is my .htaccess file:
RewriteEngine On
# Start –301 redirect for "http://" to "http://www"
Options +FollowSymLinks
rewritecond %{http_host} ^example.com [nc]
rewriterule ^(.*)$ http://www.example.com/$1 [r=301,L]
RewriteEngine On
RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /?(.*)/index\.php
RewriteRule ^(.*)$ /%1/ [L,R=301]
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/$1 [L]
This works fine.All URL works perfectly without having /index.php in it.
But my problem is when someone put a URL with index.php (for ex. https://example.com/index.php/test ). So it will also works. That's is a problem, I want that when user put the /index.php with the URL it will redirect to the same page without having /index.php in it. Please help me to sort this out.
Try adding this above the rules that you already have:
RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /?(.*)/index\.php
RewriteRule ^ /%1/ [L,R=301]
If you try to match against the request URI, it will cause a loop because the rules that you already have routes requests to index.php, rewriting the request URI to index.php thus causing it to match when rewrite engine loops.

Resources