How can I open my page without .html address? - url-rewriting

I am a beginner, so sorry for this question.
the main page name is: index.html
and a second page is for example second.html
The issue:
I can just open it on the browser by using the full name includes .html means:
www.example.com/second.html
If I type just: www.example.com/second it is not possible to open the page.
Can you maybe tell me what I do wrong?

You need to edit your htaccess, try this:
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^([^\.]+)$ $1.html [NC,L]

Related

codeigniter page not found on live server

codeigniter page not found showing but working fine in local server.
I had uploaded codeigniter file of one basic simple page on live server but there it is showing no page found and same file it is working on local server.
In that I had
mine.php ---- controller
index.php --- view
I loaded in routes default controller - mine in config base url- domain.com removed index.php also
.htaccess
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/$1 [L]
can I know please why it is showing page not found, might be some routing issue but I had loaded default controller also. Please help out on this
First of all start error logging properly so you can see the actuall error.
Change your file name's first letter capital. This is mendetory as explained here ci3 manual - controllers. It says class name as well as file name must start with capital. ( If your Dev machine is windows then it will not show errors if you don't follow this rule. Because window's file system is case insensitive. But on your server it is linux.so it will show error)
If you still don't get it working then try access the url with index.php in it. Temporaryly disable .htaccess .If you get it working then may be you have problem in . htaccess. Try the following link to properly remove index.php from your url. Expression engine forum .This htaccess worked for me on all different server I have used.
add this in .htaccess file
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond $1 !^(index\.php|images|asset|robots\.txt)
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php?/$1 [L]
</IfModule>

rewriting simple html files for SEO friendly URLS

I have a simple file mydomain.com/business_nottingham.html
and i want to re-write that to an SEO friendly URL, eg mydomain.com/business-nottingham/
I've googled all the examples but they seem to be designed for either CMSes or PHP scripts.
Is there a simple .htaccess re-write example available that allows me to do something very simple as above?
Edit: I managed to find the following code finally
Options +FollowSymlinks
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)\.html$ /$1 [L,R=301]
However, it's still not quite working. If i enter the tidy URL, i get re-directed to a 404 page, but putting in the exact .html file name gets me to the right file but doesnt present me with a clean url.
I've tried various combinations of the above by reading various articles and tutorials but for some reason it doesn't seem to work for me.
You want to redirect only when the actual request is for an .html file, then you want to internally rewrite to the html file. The way URLs resolve is the browser shows where it thinks it's going (URL in the address bar), then the request is made to the web server. If the webserver (where the htaccess file is) wants to change what's in the browser's URL address bar, it needs to tell the browser to literally load an entirely different URL. The browser will then request the new URL. Then the server must internally rewrite that URL back to where the actual resource is (the first URL), but the browser doesn't see this happen.
RewriteEngine On
RewriteCond %{THE_REQUEST} ^(GET|HEAD)\ /([^\ ]+)\.html
RewriteRule ^ /%2/ [L,R=301]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI} ^/(.*?)/?$
RewriteCond %{DOCUMENT_ROOT}/%1.html -f
RewriteRule ^ /%1.html [L]

URL Rewrite for joomla

I wanted change this joomla link
http://www.asbhtechsolutions.com/component/search/?searchphrase=all&searchword=simple%20program%20for%20java
to
http://www.asbhtechsolutions.com/search/simple-program-for-java
How can I do this?
If you don't want to write your own router for the search component, the simplest way is to add a redirect to your .htaccess file.
I don't know about your joomla version, but i checked in joomla 1.5.26,
Just got to the joomla/components/com_search/controller.php
and Search the function search(), at the bottom of this function you find the line that call the url with JRoute class.
$this->setRedirect(JRoute::_('index.php'.$uri->toString(array('query', 'fragment')), false));
now dig something your self to change according to your need, or read some documentation on Joomla JRoute, don't forget to change according to your Joomla Version.. Hope this help you..
if you don't have enough experience with .htaccess try renaming htaccess.txt file to .htaccess. It's contained in your root directory of the Joomla installation.
Oh.. I've never seen a question about .htaccess like this before, it's not easy. I do not know if the code below would work. Just give a try to test this in your .htaccess file:
Options +FollowSymlinks
RewriteEngine on
RewriteCond %{REQUEST_URI} ^/search/([a-z0-9-_]+)/?$
RewriteRule ^(.*) /component/search/?searchphrase=all&searchword=%1
RewriteCond %{REQUEST_URI} ^/search/([a-z0-9-_]+)/([a-z0-9-_]+)/?$
RewriteRule ^(.*) /component/search/?searchphrase=all&searchword=%1\%20%2
RewriteCond %{REQUEST_URI} ^/search/([a-z0-9-_]+)/([a-z0-9-_]+)/([a-z0-9-_]+)/?$
RewriteRule ^(.*) /component/search/?searchphrase=all&searchword=%1\%20%2\%20%3
RewriteCond %{REQUEST_URI} ^/search/([a-z0-9-_]+)/([a-z0-9-_]+)/([a-z0-9-_]+)/([a-z0-9-_]+)/?$
RewriteRule ^(.*) /component/search/?searchphrase=all&searchword=%1\%20%2\%20%3\%20%4

How to redirect all *.html pages to *.php pages?

I looked for the answer to this since it should be a rather common thing to do
and found some but the all lead me to an internal server error.. :(
i need to redirect all my html pages to their counter part in php
i know there is a rewriteRule i can use but cant seem to find the syntax..
a simple explenation:
i need to redirect all my *.html pages to *.php
I hope i explained it well.. would love your help or a link to some resources on this subject where i can really understand how to create this redirectRule
Create a .htaccess in the root folder of your site and place the following rules in it:
RewriteEngine on
RewriteCond %{SCRIPT_FILENAME} !-f
RewriteCond %{SCRIPT_FILENAME} !-d
RewriteRule ^(.*)\.html$ $1.php [L,R]
If you don't want the address bar to reflect the change, then change that last line to
RewriteRule ^(.*)\.html$ $1.php [QSA,L]
You can use RewriteRule:
RewriteEngine on
RewriteRule ^/(.*)\.html$ $1.php [R]
If you get Internal Server Errors, make sure that you have enabled mod_rewrite in apache :
sudo a2enmod rewrite
sudo /etc/init.d/apache2 reload

Codeigniter: how to serve static html pages in codeigniter context

Hi all
I want to serve some static html pages in codeigniter context. I dont want to bypass the index.php file in the base_url.
But when I user the call to the HTML file, it dispays the 404 error page.
I appreciate any help for this topic from guys who already solving this problem . Thanks for all in advance
I want to precise this elements:
my real problem is to serve PDF file for users to display in the browser only an not to save the PDF file. So I convert the PDF to HTML Files. The output is a directory with HTML files linked betwen them and ther images/button, CSS, js for navigation
when i put this HTML-OUTPUT in ci\Docs\HTML1 directory I can access it whith this URL localhost/ci/docs/html1/index.htm.
But where i use localhost/ci/index.php/docs/html1/index.htm I get A 404 error page.
So I moved The HMLT1 directory to the Application\views directory. And i stil have the same error. My .htacces look like this:
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteCond $1 !^(index\.php|resources|robots\.txt)
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/$1 [L,QSA]
</IfModule>
Thanks Guys for your help
Create the static HTML file as a view and then just load the view:
$this->load->view('static.html');
You can then access this file as a normal controller. It all depends on how you have set up your .htaccess as well.
For me I just add a folder name for my static html pages into the .htaccess to exclude it from regexp like below, and it work. Just to exclude it from rewrite URL to index.php
RewriteEngine on
RewriteCond $1 !^(index\.php|images|css|js|robots\.txt|sitemap\.xml|static-html)
RewriteRule ^(.*)$ index.php/$1 [L]
$route['your-page-url'] = "/page/message/your-page-url";
In your Page controller function:
public function message($page = 'your-page-url')
{
$data['title']= 'Your Page Title';
$this->load->view('/header',$data);
$this->load->view('pages/your-page-url');
$this->load->view('/footer');
}

Resources