How to remove index.php from url using .htaccess (mod_rewrite)
For better SEO optimization and make urls more search engine friendly , remove index.php from URL and make it easier to read.
Remove index.php from URL can be done by writing only two lines in your .htaccess(mod_rewrite in apache) file. Before writing this rule in .htaccess , make sure that your mod_rewrite is enabled(On) in your apache server. Most probably mod_rewrite is enabled in Linux server but for windows server , you need to contact hosting people to make mod_rewrite enabled. You can check this by looking in phpinfo().
Below is the Rules which will remove index.php from URL using .htaccess. Look at below links for .htaccess rules.
RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /([^/]+/)*index\.php\ HTTP/ RewriteRule ^(([^/]+/)*)index\.php$ http://www.%{HTTP_HOST}/ [R=301,NS,L]
Redirect 301 means Moved Permanently so most search engines will remove index.php from URL.
To know more about programming,MYSQL database,php info,php editor,programming php,Open-source,php help and php script , subscribe to our feed by entering email address below. You will get updates via email about every tutorial posted on this site . It will not take more than a sec.






I am
about 2 years ago
Yes it will be helpful for SEO purpose as it will remove index.php from URL.
It helps me as i was in search of this .htaccess rules. I found so many solutions in google but none of them works for me.
This works for me. Thanks.
about 2 years ago
Yes it will be helpful for SEO purpose as it will remove index.php from URL.
It helps me as i was in search of this .htaccess rules. I found so many solutions in google but none of them works for me.
This works for me. Thanks.
about 2 years ago
I was hopeful, but this code gives me a server error.
Thanks for posting, though.
about 2 years ago
I was hopeful, but this code gives me a server error.
Thanks for posting, though.
about 2 years ago
@abril – It works for me.. are you getting 500 server error ?
about 2 years ago
@abril – It works for me.. are you getting 500 server error ?
about 1 year ago
Yeah i'm getting Internal Server error and still find to way to fix that, It's so strange because that code is look fine …
about 1 year ago
Yeah i'm getting Internal Server error and still find to way to fix that, It's so strange because that code is look fine …
about 1 year ago
I too received the 500 server error.
This is what I want the .htaccess file to do:
> When some types http://www.thiswebsite.co.uk/index.php into their browser, the browser DOES execute the index.php page, but is DOES NOT show the "index.php" in the address bar.
Now, is this actually possible? I've searched long and hard, and every 'solution' I've found just breaks my site. What am I doing wrong? Am I confusing "remove index.php" with "hide index.php"? I do NOT want to avoid the index.php file as it controls my site, I simply want to hide the words "index.php" from the address bar.
Thanks.
about 1 year ago
I too received the 500 server error.
This is what I want the .htaccess file to do:
> When some types http://www.thiswebsite.co.uk/index.php into their browser, the browser DOES execute the index.php page, but is DOES NOT show the "index.php" in the address bar.
Now, is this actually possible? I've searched long and hard, and every 'solution' I've found just breaks my site. What am I doing wrong? Am I confusing "remove index.php" with "hide index.php"? I do NOT want to avoid the index.php file as it controls my site, I simply want to hide the words "index.php" from the address bar.
Thanks.
about 1 year ago
Hey Jal.. I would be interested to know -did you manage to sort out your index.php problem? I find myself in exactly the same situation as you, nothing seems to work for me either..still looking.
about 1 year ago
Hey Jal.. I would be interested to know -did you manage to sort out your index.php problem? I find myself in exactly the same situation as you, nothing seems to work for me either..still looking.
about 5 months ago
If you guys haven’t solved the problem (only 1 year passed by since you asked the last question, but this can be useful to someone else
), try adding this in your .htaccess file.
# RewriteBase /
# Redirect index.php Requests
# ——————————
RewriteCond %{THE_REQUEST} ^GET.*index\.php [NC]
RewriteCond %{THE_REQUEST} !/system/.*
RewriteRule (.*?)index\.php/*(.*) /$1$2 [R=301,L]
RewriteCond %{THE_REQUEST} ^GET
# Standard ExpressionEngine Rewrite
# ——————————
RewriteCond $1 !\.(css|js|gif|jpe?g|png) [NC]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ /index.php/$1 [L]
#
## End – Joomla! core SEF Section.
about 4 months ago
Thanks Irena,
it work find for my site i use below code:
# Redirect index.php Requests
# ——————————
RewriteCond %{THE_REQUEST} ^GET.*index\.php [NC]
RewriteCond %{THE_REQUEST} !/system/.*
RewriteRule (.*?)index\.php/*(.*) /$1$2 [R=301,L]
RewriteCond %{THE_REQUEST} ^GET
about 4 months ago
No problem
)
about 3 months ago
please help zazavi (Advanced Search Engine Friendly URLS)
ZAZAVI CMS FREE PROJECT (OPEN SOURCE)
in this below default URL,and 3 is page id in database.
i want complete secure URL. & totally look like static webiste.
http://localhost/zazavi/3/contact.html
i want this (e.g.)
http://localhost/zazavi/contact.html