website links messed up // .htaccess - php

I screwed up my .htaccess` file and now my links are messed up.
for example www.cardler.com/contact.php changes to www.cardler.com/awstats/contact.php
if you manually type in cardler.com/contact.php it works...
Link: www.cardler.com/index.php - try it out by clicking on the contact button.
.htaccess
RewriteEngine on
DirectoryIndex index.php
RewriteCond %{REQUEST_FILENAME}.php -f
RewriteCond %{REQUEST_URI} !/$
RewriteRule (.*) $1\.php [L]

Related

Hide PHP file extension on URL (Even when someone manually puts .php at the end)

My .htaccess file:
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}.php -f
RewriteRule ^(.*)$ $1.php
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}.html -f
RewriteRule ^(.*)$ $1.html
</IfModule>
Hello currently my system works fine and I can have links without .php at the end, but I want to go one step further, and make it so if someone was to enter .php at the end manually for if the link is www.example.com/account
Changing it to www.example.com/account.php would produce a 404 error?
Is this possible?
Thank you very much, I am very grateful for any responses I get!
You can insert this rule just below RewriteEngine on line:
RewriteEngine On
# To externally redirect /dir/file.php or /dir/file.html to /dir/file
RewriteCond %{THE_REQUEST} \s/+(.+?)\.(?:php|html?)[\s?] [NC]
RewriteRule ^ - [R=404,L]
# your existing rules go below this
This will return 404 for www.example.com/account.php or www.example.com/account.html

Why do I need to add index.php in order to route my website correctly? [getkirby]

I uploaded the code to the server. It started the homepage correctly . But when I press any link , I get 404 not found error. I discovered that I need to add index.php to my url for it to work.
so it will be like that:
mydomain.somee.com/myWebsite/index.php/anotherPage
When I was working locally using Xamp as a server, I didn't get any of those problems.
I got those problems after I uploaded the website to some.com which apparently doesn't use .htaccess file (editing or removing has no effect).
How to add this index.php automatically and hide it from the user?
I didn't change any of the system files or the htaccess
please tell me if you need anymore files or description.
You need to redirect all your all pages through index.php file but remove it from URL.
Write below rules in your root .htaccess file:-
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ /index.php?/$1 [L]
OR
Options +FollowSymLinks -MultiViews
# Turn mod_rewrite on
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php?$1 [L,QSA]
RewriteCond %{THE_REQUEST} ^[A-Z]{3,}\s(.*)/index\.php [NC]
RewriteRule ^ %1 [R=301,L]
To understand, How htaccess rules are working, This link will help you :)
Hope it will help you :)

removing .html URL extension using .htaccess not working

I'm using the below code to remove .html extention form url, but it is not working..
can any one help , where i have to put the .htaccess file
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}\.html -f
RewriteRule ^([^/]+)/$ $1.html
I would like to share an understandable, simple way to remove the .html extension from the URL using the .htaccess file. I'm using XAMPP on Windows 10. For me, it's working perfectly. If you want the same result, just follow the steps given below...
For removing the .html extension, e.g. if you want to change mywebsite.com/contact.html to mywebsite.com/contact you have to add the following code inside your .htaccess file:
First of all, create a new file named .htaccess and placed it at your root-directory where your index file is placed.
Now, open this (.htaccess) file with any editor of your choice and write/copy/paste the given code in your file and save it...
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^([^.]+)$ $1.html [NC,L]
Now, if you (any user) will access mywebsite.com/contact in the browser, it will show the content of mywebsite.com/contact.html page.
So, what if any user will access the URL as mywebsite.com/contact.html? this will redirect the user to this mywebsite.com/contact.html page instead of this mywebsite.com/contact which means the user can still visit the mywebsite.com/contact.html page. Don't worry about it. If you want to avoid this, the next step is for you...
To avoid the above problem and for redirecting users to the newly created URL, you need to add some more rules in your .htaccess file. So, open it again and replace your old code with the new one given below and save your file...(You can ignore this step, It's on you...)
RewriteEngine On
RewriteCond %{THE_REQUEST} /([^.]+)\.html [NC]
RewriteRule ^ /%1 [NC,L,R]
RewriteCond %{REQUEST_FILENAME}.html -f
RewriteRule ^ %{REQUEST_URI}.html [NC,L]
Now, you're all set.
I hope this will fix everyone's problem.
Have a nice day :)
You can use this code in your DOCUMENT_ROOT/.htaccess file:
RewriteEngine On
RewriteBase /
RewriteCond %{THE_REQUEST} \s/+(.+?)\.html[\s?] [NC]
RewriteRule ^ /%1 [R,L]
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}.html -f
RewriteRule ^(.+?)/?$ $1.html [L]
Finally I Got the correct .HTACCESS code to remove .php extention... :)
Options +FollowSymLinks -MultiViews
# Turn mod_rewrite on
RewriteEngine On
RewriteBase /
## hide .php extension
# To externally redirect /dir/foo.php to /dir/foo
RewriteCond %{THE_REQUEST} ^[A-Z]{3,}\s([^.]+)\.php [NC]
RewriteRule ^ %1 [R,L,NC]
## To internally redirect /dir/foo to /dir/foo.php
RewriteCond %{REQUEST_FILENAME}.php -f
RewriteRule ^ %{REQUEST_URI}.php [L]
Use this
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}.html -f
RewriteRule ^(.*)$ $1.html [NC,L]

Rewrite URL with .htaccess to hide PHP extension

I've a question, I'm developing a webservice for a specific app.
Last week I transferred my back-up from server1 to server2, since that moment my .htaccess won't work anymore.
The url for my webservice is:
http://apps.holtesdesign.nl/inholland/apiv0/
This url works fine, to load the bugreport module:
http://apps.holtesdesign.nl/inholland/apiv0/bugreport.php
But the url was supposed to be:
http://apps.holtesdesign.nl/inholland/apiv0/bugreport
When you'll open the last url, you'll see that it will result in an internal server error.
Do you know how it's possible?
My .htaccess looks like:
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}\.php -f
RewriteRule ^(.*)$ $1.php
The server is running on CentOS, and I've already checked if mod_rewrite is functioning...
I hope you can help me guys!
Cheers,
Jelmer
This will fix it:
RewriteEngine On
RewriteCond %{REQUEST_FILENAME}.php -f
RewriteCond %{REQUEST_URI} !/$
RewriteRule ^(.*)$ $1\.php
If it doesn't work correct the settings of your Wamp Server:
Left click WAMP icon
Apache
Apache Modules
Left click rewrite_module.
This will hide the trailing slash and hide .php in root & sub directories.
RewriteEngine On
RewriteCond %{THE_REQUEST} ^[A-Z]{3,}\s([^.]+)\.php [NC]
RewriteRule ^ %1 [R=301,L]
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}.php -f
RewriteRule ^(.*?)/?$ $1.php [NC,L]
Working Concept for me:
# Options is required by Many HostSevice
Options +MultiViews
RewriteEngine on
# For .php & .html URL's:
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^([^\.]+)$ $1.php [NC,L]
RewriteRule ^([^\.]+)$ $1.html [NC,L]
Use this code in Root folder of your website in .htaccess File : Example
offline - wamp\www\YourWebDir
online - public_html/
Important Note : If it doesn't work correct the settings of your Wamp
Server: 1) Left click WAMP icon 2) Apache 3) Apache Modules 4) Left
click rewrite_module
try this.. it works! :)
Options +FollowSymLinks
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}\.php -f
RewriteRule ^(.*)$ $1.php

Want to display .php file as without extension?

my url is :http://www.example.com/home.php i want to show it when enduser navigates my site as http://www.example.com/home. I know this can be done through .htaccess file.
Following is the htacces file:
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}.php -f
RewriteRule ^(.+)$ $1.php
Nothing is happening with the above code in .htaccess file.I want to show entire site pages without .php extension.Can anyone suggest me how to do this
Try this
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}\.php -f
RewriteRule ^(.*)$ $1.php
</IfModule>

Categories