Automatically add index.php to end of URL - .htaccess

When the user visits my site, the URL displayed is http://example.com.
How do I automatically add /index.php to the end of the URL to make it http://example.com/index.php?

Use DirectoryIndexRedirect directive
DirectoryIndexRedirect on

You could try something like this:
RewriteEngine On
RewriteRule ^/$ http://%{HTTP_HOST}/index.php [R=301,L]
But why would you want that?

Related

HTACCESS moving pages and masking

I have the current domains
http://domain.com/dev/programme and http://domain.com/dev/software
But I want to point them to http://domain.com/dev/programmes http://domain.com/dev/softwares
I have set up the following htaccess
Redirect 301 /new/programme http://www.domain.com/new/programmes/
Redirect 301 /new/software http://www.domain.com/new/softwares/
This works but the problem comes when you try access sub pages of the main links. The sub pages rely on the slug in the url.
eg. http://domain.com/dev/programme/page and whenever I try access this page with htaccess set like the above it sends me on a redirect loop.
How would I be able to keep the link like http://domain.com/dev/programme/page but have it http://domain.com/dev/programmes whenever its accessed?
Try this:
RewriteEngine On
RewriteRule ^dev/programme$ dev/programmes [L]
RewriteRule ^dev/software$ dev/softwares [L]
RewriteRule ^dev/programme/(.*)$ dev/programmes/$1 [L]
RewriteRule ^dev/software/(.*)$ dev/softwares/$1 [L]
You can do this in a single rewrite rule:
RewriteEngine On
RewriteRule ^(dev/programme|software)(/.*)?$ /$1s$2 [L,NC]

Redirect /index.php from the end of the URL

Have a website with subpages all in this format:
mydomain.com/something
That's fine. But what is NOT fine is that you can also do mydomain.com/something/index.php (you can enter address in this format into your browser) and you still get the content on that mydomain.com/something.
I don't want those two possibilites to be available at the same time, Google doesn't like this. I want just one to be possible.
So what I want to do is whenever you type into your browser mydomain.com/something/index.php, you will be redirected to mydomain.com/something (without that /index.php at the end).
How should I write a .htaccess code to do something like this?
add the following lines to .htaccess in the root directory of your website
RewriteEngine on
RewriteCond %{ENV:REDIRECT_STATUS} !200
RewriteRule ^(.*?)/?index.php$ /$1 [R=301,L,NC,QSA]
Note: the first condition assure that no previous redirection is made (to prevent redirection loop)
Mordor:
You can try this in your .htaccess file:
RewriteCond %{THE_REQUEST} ^.*/index.php
RewriteRule ^(.*)index.php$ /$1 [R=301,L]

301 Dynamic Pages Redirect

Hi I tried various methods with modewriter in htaccess shown in other threads. I want to redirect my url from www.example.com/categories.php?category=1 to www.example.com/categories/science.
I would really appreciate an example too where I'm wrong. Thank You.
Assuming that it is just this one URL you want to redirect it would be like:
RewriteEngine on
RewriteCond %{QUERY_STRING} ^category=1$ [NC]
RewriteRule ^categories.php$ www.example.com/categories/science/? [L,R=301]
This is in case you are using a .htaccess file, otherwise add a prepending slash:
RewriteRule ^/categories.php$ www.example.com/categories/science/? [L,R=301]
The querystring wil be discarded. Only put [R] if you want to show it to the user in the addressbar of the browser. Consider which status you want to serve, Google likes 301 if it's permanent.
Next you have to catch the incoming request with an index.php in the directory www.example.com/categories/science
good luck!

Strange htaccess redirect

Whats is wrong with my htaccess here..
RewriteEngine on
Options -Indexes
IndexIgnore *
RewriteRule ^page somepage.php [L]
Im try redirect http://mysite.com/somepage.php to http://mysite.com/page and this working fine, but i can also access to this url http://mysite.com/page2121 or http://mysite.com/pageasd4a4sd ... and all is redirected to same page somepage.php, what is wrong here..
Add the $ at the end of page like the following:
RewriteRule ^page$ somepage.php [L]
Assuming you mean redirect /page to /somepage.php, you need to explicitly set the end of the pattern, write now, yours is matching everything that starts with page, not starts and ends with page. Try this:
RewriteEngine on
RewriteRule ^page$ somepage.php [L]
(the $ is key)

.HTACCESS redirect /calendar to /events

I need to redirect all traffic from /calendar to /events.
www.domain.com/calendar/sales to redirect to www.domain.com/events/sales
So I need to replace calendar with events anyone who goes to the main calendar page, www.domain.com/calendar will be redirect to www.domain.com/events
Use the rewrite rule
RewriteEngine On
RewriteCond %{REQUEST_URI} ^/calendar.*$
RewriteRule /calendar((/.*)?)$ /events$1 [QSA,R=301]
In your VirtualHost context.
You need to load mod_rewrite for it to work.
You may try something like this:
RewriteEngine On
RewriteRule ^calendar/(.*)$ events/$1 [R=301,L]
Best
Marco

Resources