Is there a way to link to the index page of a website without specifying the name of the index page or the full website URL?
I have this:
Home
But when I click the link, my address bar shows:
mydomain.com/index.html
I would like it to show:
mydomain.com
Can I do that without putting the full URL (mydomain.com) in the href? If so, how?
For future viewers, I also found this question helpful.
You can just do this:
Home
Any href preceded by a slash is relative the root directory.
It should be noted that when viewing a webpage from a local hard drive in a browser, this will cause the link not to function.
I know this post is old and has an answer. But here is my contribution that also supports index that is not exactly in the root directory
to goto
mydomain.com/index.html
without index.html showing in address bar
Home
this will always point to mydomain.com no matter where the directory your file was saved to.
to point to the index in a directory use this:
Home
this will point to mydomain.com/subdir for mydomain.com/subdir/index.html while the accepted answer will always point to mydomain.com (and this is not always the desired action)
Create a ".htaccess" file and upload to your host public folder
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /index\.html\ HTTP/
RewriteRule ^index\.html$ http://www.yourwebsite.com.ph/ [R=301,L]
RewriteCond %{THE_REQUEST} \.html
RewriteRule ^(.*)\.html$ /$1 [R=301,L]
</IfModule>
Related
How can I redirect every index.html file to /
For example redirect this URL: https://www.example.com/contact/index.html to https://www.example.com/contact/
Note: I don't want to redirect to the root, I want to redirect to the same directory just remove the index.html
Thank you in advance for your time
Assuming you are using Apache the following lines in .htaccess file under the /contact folder will do the trick:
RewriteEngine On
RewriteBase /
RewriteRule ^(.*)/index.html$ %{CONTEXT_PREFIX}/folder/$1/ [R=301,L]
RewriteRule ^index.html$ %{CONTEXT_PREFIX}/folder/ [R=301,L]
where folder is contact in your example.
Earlier I suggested using the following rule for a shortcut of the above two:
RewriteRule ^(.*)index.html$ %{CONTEXT_PREFIX}/folder/$1 [R=301,L]
However, this has an unwanted side-effect of redirecting say something like https://www.example.com/contact/myindex.html to https://www.example.com/contact/my
Note: Please be careful not to cause redirection "loops" like:
xxx/index.html -> xxx/ -> xxx/index.html -> xxx/ ...
I have an html link:
Link
I formatted the link destination with a htaccess file:
RewriteRule ^destination$ index.php?content=destination [L,NC,QSA]
The question is: How can I give a ID via URL to the destination?
the full link will be index.php?content=destination?ID=x
X will be a dynamic number
but I would like to show this in the url - it should be invisible.
But I don't know how I have to modify the rewriteRule to realize it.
Although not a pretty solution and it obviously comes with flaws, you could always use cookies.
set a cookie in PHP:
setcookie("page_id","987987");
and look for it in htaccess
RewriteCond %{HTTP_COOKIE} ^page_id=([0-9]*)$ [NC]
RewriteRule ^destination$ index.php?content=destination&id=%1 [L,NC,QSA]
I have a static website that has several html pages. In order to not hide .html extensions from url, we have following rules in htaccess for each url:
RewriteRule ^website-development$ website-development.html
This works fine in that if you open site.com/website-development, it actually opens the website-development.html file but in url it does not show the .html extension.
Now, we need to redirect(or hide) .html urls to their corresponding urls without .html e.g. if someone opens site.com/website-development.html in their browser, the url should be shown as site.com/website-development.
To do this, I added following rule:
RewriteRule ^(.*)\.html$ /$1 [L,R]
But doing this results in indefinite redirection and so the browser just keeps redirecting and never renders the actual page. Can you please suggest how I can redirect both site.com/website-development and site.com/website-development.html to site.com/website-development (which actually is an html file - website-development.html ). Thanks.
Yes indeed, this rule will cause a redirect loop:
RewriteRule ^(.*)\.html$ /$1 [L,R]
It is due to the fact your REQUEST_URI is adding and removing .html in 2 different rules and mod_rewrite runs in a loop.
You can use this rule instead based on a RewriteCond that uses THE_REQUEST
RewriteCond %{THE_REQUEST} \s/+(.+?)\.html[\s?] [NC]
RewriteRule ^ /%1 [R=301,NE,L]
THE_REQUEST variable represents original request received by Apache from your browser and it doesn't get overwritten after execution of some rewrite rules. Example value of this variable is GET /index.php?id=123 HTTP/1.1
I'm new to hosting and I'm trying to get a basic "index of" page to show.
I have an address ie: www.mydomain.com/files
I just have some zip files in that location that I'd like to show and allow users to download but not sure how to do this. At the moment I just get a FORBIDDEN page.
Create an .htaccess file and put
Options +Indexes
In it.
try this :
Rewritecond %{HTTP_HOST} ^example\.com
RewriteRule ^(.*)$ http://www.example.com/$1 [R=301,L]
I have a two files in my root folder: main.html and index.php.
Well, normally index.php takes places as it has higher priority to respond, just wanted to change the logic, so then at first the user has to visit the main.html and then get redirected to index.php. I tried the below code in my .htaccess but it doesn't work as I expected. Actually after doing that, now the first page is correctly changed to main.html, but it never get redirected to index.php!!! It actually returns to main.html again and again (like loop!)
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>
DirectoryIndex main.html /main.html
ps:
1- even if i try to request the index.php it will open main.html instead!
You can change the default page for directory using the following in your htaccess file, as you have done in the question. Users would land on main.html (instead of index.php) when navigating to "www.coolsite.com/".
//Change default directory page
DirectoryIndex main.html
To redirect the user to another page, you can use the following:
window.location = "http://www.coolsite.com/index.php";
Well, it seems wordpress and static content [index page!] does not not come along! (mostly because of the existing RewriteRule[s] + WP internals)
The workaround is to create a 'page template' (the static content you wish to display as index page) and ask WP to display it as Front-page .