.htaccess redirect index.php to / - linux

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]

Related

.htaccess rewrite URL without its change

I'm trying to make www.site.com/web/name to be understood as www.site.com/web?system=name (without the change in URL)
Options +FollowSymLinks
RewriteEngine On
RewriteCond %{REQUEST_URI} !(/$|\.)
RewriteRule (.*) %{REQUEST_URI}/ [R=301,L]
RewriteRule ^([a-zA-Z0-9_-]+)/([a-zA-Z0-9_-]+)$ $1?system=$2
RewriteRule ^([a-zA-Z0-9_-]+)/([a-zA-Z0-9_-]+)/$ $1?system=$2
.htacceess is located in /web.
This doesn't do anything! Where is my mistake?
You may use these rules in web/.htaccess:
Options +FollowSymLinks
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_URI} !\.
RewriteRule [^/]$ %{REQUEST_URI}/ [R=301,L,NE]
RewriteRule ^([\w-]+)/?$ ?system=$1 [L,QSA]

htaccess redirect 301 https www to non www

Currently only the homepage is redirecting from www.example.com and example.com to https://example.com
I try to redirect:
1. http://www.example.com/otherpages to https://example.com/otherpages
2. http://example.com/otherpages to https://example.com/otherpages
3. https://www.example.com to https://example.com
3. https://www.example.com/otherpages to https://example.com/otherpages
Tried to use some former questions but can't figure it out.
current state in .htaccess is:
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
RewriteCond %{SERVER_PORT} 80
RewriteRule ^(.*)$ https://my-domain.com/$1 [R=301,L]
RewriteCond %{HTTP_HOST} ^www\.(.*)$ [NC]
RewriteRule ^(.*)$ https://%1/$1 [R=301,L]
RewriteCond %{HTTP_HOST} ^www\.my\-domain\.com [NC]
RewriteRule ^(.*)$ http://my-domain/$1 [L,R=301]
</IfModule>
Thanks in advance
You don't need all that code for the conditions you want. Replace your all of that code with this and change to your domain.
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteCond %{HTTPS} !^on [OR]
RewriteCond %{HTTP_HOST} !^example\.com$ [NC]
RewriteRule ^(.*)$ https://example.com/$1 [R=301,L]
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>

Url Rewrite - Add Query String Too 999

DirectoryIndex index.php
<IfModule mod_rewrite.c>
RewriteEngine On
#RewriteBase /
RewriteCond %{REQUEST_URI} ^(.*)//(.*)$
RewriteRule . %1/%2 [R=301,L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^.*$ index.php?qa-rewrite=$0&%{QUERY_STRING} [L]
RewriteRule ^tags tags.php [L,NC]
</IfModule>
i want to add new page .but write page not found. why? please help me.
RewriteRule ^tags tags.php [L,NC] // i want this www.example.com/tags open tags.php ?
You need to reorder your htaccess rules like this :
DirectoryIndex index.php
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_URI} ^(.*)//(.*)$
RewriteRule . %1/%2 [R=301,L]
RewriteRule ^tags/?$ tags.php [L,NC]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^.*$ index.php?qa-rewrite=$0&%{QUERY_STRING} [L]
</IfModule>
The problem is that, your rule
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^.*$ index.php?qa-rewrite=$0&%{QUERY_STRING} [L]
Rewrites any request (not a true file/dir) to index.php. since /tags is not an existent file on your directory, so a request for http://example.com/tags was being rewritten to /index.php and the last rule(s) never executed.

Removing index.php from subdomain

I have the following .htaccess file in my subdomain.
My website has http://hello/forum/index.php, and would like to hide this index.php file, and make it http://hello/forum.
Whenever I use the attached .htaccess, it directs to http://hello, not http://hello/forum. Am I missing something?
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteCond %{THE_REQUEST} ^GET.*index\.php [NC]
RewriteCond %{REQUEST_URI} !/system/.* [NC]
RewriteRule (.*?)index\.php/*(.*) forum/$1$2 [R=301,NE,L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ forum/index.php/$1 [L]
</IfModule>
Try these rules:
RewriteCond %{THE_REQUEST} ^GET\ /(forum)/index\.php [NC]
RewriteRule ^ /%1 [R=301,L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ /forum/index.php/$1 [L]
I was able to solve this issue by adding
DirectoryIndex index.php index.html
in .htaccess file.

Change URL with rewrite rule

How can I change my URL from domain.com/sprekers/?spreker=value to domain.com/value with a rewrite rule with wordpress.
I've tried to change it like this
RewriteCond %{QUERY_STRING} ^spreker=(.*)$
RewriteRule ^sprekers/$ %1/? [R=301,L]
than I tested it with the htaccess tester http://htaccess.madewithlove.be If I test it on the tester everything works fine but when I do this on my wordpress site it doesn't work. This is my complete htaccess file:
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
RewriteCond %{QUERY_STRING} ^spreker=(.*)$
RewriteRule ^sprekers/$ %1/? [R=301,L]
</IfModule>
I think it doesn't work because the /sprekers is already "made" by wordpress how can I fix this?
Cheers
Robin
I think, you need to put your first code after the RewriteBase / rule.
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteCond %{QUERY_STRING} ^spreker=(.*)$
RewriteRule ^sprekers/$ %1/? [R=301,L]
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>

Resources