Default Page Display in Address Bar using .htaccess - .htaccess

I wanted a htaccess file which would set the Default page for a directory and also display the file name in the address bar.
For example:
In general, if index.html is the Index file, then typing the address http://www.example.com/ would be internally loading http://www.example.com/index.html but by default the /index.html is not displayed in the address bar. How can we display it.
Like if user enters http://www.example.com then the address should change to http://www.example.com/index.html
Please Help
Thanks

Redirect from www.example.com to www.example.com/index.html, using mod_rewrite.

Related

Redirecting to other webpage without changing address

I have a webpage http://example.com. Using the htaccess file I'm redirecting users to the page https://other_domain.com:8081 if they type http://example.com/page in their browser. That works well but the problem is that when redirected, https://other_domain.com:8081 appears in the address bar of the browser. I have added the the following to the top of the htaccess file of the http://example.com webpage but still https://other_domain.com:8081 is shown as the address after redirection:
RewriteEngine On
RewriteRule ^page(.*)$ https://other_domain.com:8081$1 [L,P]
Redirect /page https://other_domain.com:8081
How can this be resolved so that http://example.com/page is shown in the address bar instead of https://other_domain.com:8081?

htaccess - redirect parent folder to file within parent folder

I'm attempting to redirect the user to a file within a folder if the user types the folder's address as a URL.
For example:
https://www.example.com/shop
should redirect to:
https://www.example.com/shop/en_GB/index.html
I've tried to do it using a htaccess file in the root with the following rule:
Redirect 301 /shop https://www.example.com/shop/en_GB/index.html
but this does not work - it adds the file URL over and over again in the address bar.
Can anyone help? Thanks.
Redirect directive matches any URI pattern that starts with the given string. Hence you're getting a redirect loop.
You should use RedirectMatch directive for this purpose that supports regex and allows you to match precise strings.
RedirectMatch 301 ^/shop/?$ /shop/en_GB/index.html
Make sure to use a new browser for your testing or clear browser cache completely.

Redirect a Rewrite URL Address

Adding this to my .htaccess file works to shorten the URL and get rid of the .shtml bit.
RewriteEngine On
RewriteRule about about.shtml
But, the original address http://xxx/about.shtml also still exists. I don't want Google or anyone to see that one, so I tried redirecting it to the rewritten URL:
Redirect 301 /about.shtml /about
This gives an error on Firefox that it's not working and on Google that it is being redirected too many times. Maybe it's going in some sort of a loop.
I don't want the original file to show up anywhere in the web address (with the.shtml ending), so not sure what else besides a redirect to do.
Thanks!

Redirect from default page to another page using .htaccess

I want to redirect the user from the default page index.php to another page.
i.e: http://www.example.com/project/ to http://www.example.com/project/main/ar/
I tried this Redirect / /main/ar/, but insted it redirects to http://www.example.com/main/ar/project/
What is the wrong?
Maybe try
Redirect /project/ /project/main/ar/
Depending of if you need to redirect all children paths of project you may want to look at this thread -> .htaccess 301 redirect path and all child-paths

.htaccess RewriteRule is changing URL in address bar when I won't want it to

Okay first of all, I want to make my URLs prettier using .htaccess, and I've never done this before. (I'm developing a website on my local machine and viewing the pages with EasyPHP 12.1)
If I type in
/localhost/me/about/ I want it to serve the contents of
/localhost/me/about.php WITHOUT changing the URL in the address bar.
If I type in
/localhost/me/about.php I want it to serve up the contents of that file, then CHANGE the address bar to read
/localhost/me/about/
Here's my entire .htaccess file so far, and yes it's in the root of my directory, the same directory with all of the .php files:
Options +FollowSymlinks
RewriteEngine on
RewriteRule ^(.*)/$ http://localhost/me/$1.php
This successfully redirects from localhost/me/about/ to localhost/me/about.php (and it works for all of my other pages too). The thing is, I DO NOT want the URL to change in the address bar. Everywhere I look online, I see that I'm supposed to add the [R] flag at the end of my third line if I DO want the address bar updated. I don't have the flag, but the URL in the address bar still changing. What am I missing? Is there a flag I can add to force it not to change?
You have to use the [L] flag at the end of third line. The link will be internally forwarded so you can keep your localhost/me/about/ in the address bar.

Resources