Website directs to page with .html after a few clicks? - .htaccess

I have a website here:
www.arshak.co.uk
When you go on say, www.arshak.co.uk/about
It will work.
But on that webpage if you were to go on the contact page, the url won't have .html, but if you redirect yourself to another webpage from the webpage you are on, then the .html appears.
How to stop this?
This is my navbar code:
<font color="white"><p>Home</p></font>
<font color="white"><p>My YouTube</p></font>
<font color="black"><p>Personal Aims</p></font>
<font color="white"><p>Contact Me</p></font>
<font color="white"><p>About Me</p></font>
This is my .htaccess code:
Options -MultiViews
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^([^\.]+)$ $1.html [NC,L]
Help!

Related

Redirecting to another page - htaccess

I'd like to redirect the user to a page named test.php when he types the url of my site (example www.domain.com).
Pratically by typing www.domain.com the browser should show www.domain.com/test.php
At index.html or index.php, you could add meta refresh tag like this :
<meta http-equiv="refresh" content="5;www.domain.com/test.php" />
If you use index.php, the syntax would be like this:
echo '<meta http-equiv="refresh" content="5;www.domain.com/test.php" />';
Add http:// at the url if You want to redirect to another domain.
In top of your .htaccess file try this rules (except files and directories rewrite anything www/non www to example.com/test.php)
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{HTTP_HOST} ^(www\.)?example\.com [NC]
RewriteRule (.*) http://example.com/test.php [L]
</IfModule>

Styles and files not working after .htaccess rewrite rule

I've just added a simple rewrite rule to my .htaccess file to drop .php from this page http://themeat.in/register.php
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^([^/]+)/$ $1.php
RewriteRule ^([^/]+)/([^/]+)/$ /$1/$2.php
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI} !(\.[a-zA-Z0-9]{1,5}|/)$
RewriteRule (.*)$ /$1/ [R=301,L]
but now when I go visit that page without the .php (http://themeat.in/register/) all my styles and files have vanished. When I open up the console I see the page name is being treated as a folder.
This is what the file path should be and was before the rewrite, http://themeat.in/css/styles.css
and this is what it is now,
http://themeat.in/register/css/styles.css
I guess it's got something to do with the trailing slash within the rewrite but I'm totally stumped at how to fix this problem? I need the .php dropped and I'd like to keep the trailing slash.
Any help would be greatly appreciated.
Many thanks,
//C
This is because of the rewritten urls. when the url is example.com/register/ apache thinks /register/ is a directory and appends that in front of all relative urls.
To solve this, You can add the following base tag in head section of your webpage :
<base href="/">
For more info, see this post : Seo Friendly Url css img js not working

htaccess with redirect page in php

I write the following code on htaccess
Options -Indexes
RewriteEngine on
RewriteBase /localhost_site_name/
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^([^/]+)/$ ?page=$1 [L]
# 404 redirect page start
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ error.php [L]
#404 redirect page end
I am displaying pages based on page concept so I will check the page before to displaying that details on page.
This is my index file
<?php
session_start();
ob_start();
?>
<!DOCTYPE html>
<body>
<?php
//echo "Page name is ".$page;
if($page=="template" || $page=="user")
{
include("modal.php");
include("topnav.php");
include("sidebarnav.php");
include("content.php");
include("footer.php");
}
else
{
echo "<h1 style='background:#000;color:#fff;'>404 Error</h1>";
}
?>
</body>
</html>
Now my problem is when i display the pages with one argument based on my page name its shows correctly
But when i try to pass argument with that it always went to 404 page
I couldn't find out that why its happening
So help me to pass two argument with htaccess used on page concept
working url: http://localhost/sitename/pagename/
not working url: http://localhost/sitename/pagename/argument

Htaccess Rerwite Urls

RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}\.php -f
RewriteRule ^(.*)$ $1.php
RewriteRule ^hash/([a-zA-Z0-9_-]+) hash.php?key=$1 [QSA,L]
so that transforming url from
hash.php?key=anything
To
hash/anything
Works fine
But when i goes to hash/anything all urls in page have this schema
hash/anything/some_image.jpg
but i want to refer all links to root because that is meanningless
hash/some_image.jpg
so how can i refer all links to root when iam navigating to diffrent hashes !!
Just add this in your html page header:
<base href="/">

CodeIgniter Assets Not Found

Please help with CodeIgniter assets. I tried most of the solutions from StackOverflow (including the autoload utility helper), nothing works so far. Here's my setup below:
Folder Path:
.htaccess
<IfModule mod_rewrite.cs>
RewriteBase /hnk_ci
RewriteEngine On
RewriteCond $1 !^(index\.php|assets|robots\.txt)
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/$1 [L]
</IfModule>
When I view source code, it looks like this:
<link href="http://localhost/hnk_ci/assets/css/bootstrap.min.css" rel="stylesheet">
But when click on the css link from source code, I get this error:
The requested URL /hnk_ci/assets/css/bootstrap.min.css was not found on this server.

Resources