Danish Subhu
Danish Subhu

Reputation: 73

URL Rewriting I don't want to show index.php in url

I am running my php applications on

http://localhost:8085/

My Directory Structure is like this: C:\wamp\www\website

I have placed the .htaccess file in website folder.

<IfModule mod_rewrite.c>
#Turn on the RewriteEngine
RewriteEngine On
RewriteBase /website/
#Rules
RewriteRule ^(.*)$ index.php
</IfModule>

When ever i click on the index.php it takes me to the http://localhost:8085/ home page which is wrong i want to got to http://localhost:8085/website.

Please guide me

Upvotes: 0

Views: 1761

Answers (1)

Rohan Kumar
Rohan Kumar

Reputation: 40639

You need to add your website before index.php like,

RewriteRule ^(.*)$ /website/index.php

Updated, try the full code,

RewriteEngine On
RewriteBase /website/
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /website/index.php [L] 

Note: You need to use http://localhost:8085/website/ as base URL in every link which is used in your site, otherwise it will redirect to http://localhost:8085/ like,

<a href="http://localhost:8085/website/index.php">Home page</a>

Alternatively, do not use a / before any href and use your file name as it is for example,

<a href="index.php">Home page</a>

If you are using <a href="/index.php">Home page</a> it will redirect to index page of URL http://localhost:8085/

You can make a Virtual Host to access it directly https://httpd.apache.org/docs/current/vhosts/name-based.html

Upvotes: 2

Related Questions