.htaccess file not working at all - php

I am trying to redirect anyone when he is trying to hit "192.168.21.3:8080/ping" to "192.168.21.3:8080/ping.php" via creating a .htaccess file with following code in it:
//301 Redirect Old File
Redirect 301 http://192.168.1.234:8080/ping http://192.168.1.234:8080/ping.php
Also, following line in httpd.conf has been un-commentated:
LoadModule rewrite_module modules/mod_rewrite.so
Please help!

i am still learning the basics myself however i will have a try to help you out, If you let me know how you get on.. i can re-edit my answer should the solution not work.
You can either redirect all traffic to the page named ping.php or as per your question you can redirect a specific IP address to ping.php.
add the code below to your .htaccess file.
RewriteEngine On
RewriteCond %{REMOTE_ADDR} 192\.168\.21\.3
RewriteCond %{REQUEST_URI} !/ping\.php$
RewriteRule $ /ping.php[R=301,L]
Alternatively you could take a look here as this may also help you out: https://perishablepress.com/permanently-redirect-a-specific-ip-request-for-a-single-page-via-htaccess/
Thanks

Just add
RedirectMatch ^/ping$ http://192.168.1.234:8080/ping.php
to your www-root .htaccess. Nothing more.

Related

Go to file by link

I store data in text file.
And when user enter in address bar something like
my_syte.com/aaa - (without extension)- I need to file_get_contents aaa.txt file
my_syte.com/bbb - I need to file_get_contents bbb.txt file
Please advise the most powerful way of do it. Apache server.
Thanks
On Apache servers you can use mod-rewrite in .htaccess file:
RewriteEngine on
RewriteRule ^([a-zA-Z]+)$ /$1.txt [L]
if your files can contain - or _ or numbers then use:
RewriteEngine on
RewriteRule ^([a-zA-Z0-9_-]+)$ /$1.txt [L]
On nginx servers it's more complicated but some of them works with .htaccess. On other servers there may be entirely different approach. It's hard to help you without more informations.
As you said it's Apache, then use examples above. Either edit or create .htaccess file on your webroot (directory which is accessed by domain). First check if it were there (could be hidden) and if it exists then only edit it (add lines at the top).
If it doesn't exist, then create one by yourself.
Can you please give us some insights about your server? Apache nginx?
In Apache, you can achieve that with url rewriting.
Enable mod_rewrite in apache
Put the following line of code in .htaccess on the same location of my_site.com/
RewriteEngine on
RewriteRule ^/foo$ /foo.txt [PT]
to make it generic
RewriteEngine on
RewriteRule ^/*$ /foo.txt [PT]
Maybe I am wrong in sytax based on your specific server configuration. You need to make the best possible regular expression for this case.

.htaccess direct domain to subdirectory

I am trying to redirect www.example.com to /example/ on my webserver, but it appears to only be redirecting the index.php page. An additional issue is the main file displays as http://tunedu.com/tunedu/ when I would like it to display as tunedu.com
Live example:
This page works: http://tunedu.com/tunedu/
This page doesn't work: http://tunedu.com/school.php?id=75
Any regex changes I do try end up just breaking everything. The .htacess code is this:
RewriteEngine on
RewriteRule ^$ /tunedu/ [L]
Thanks.
The proper way to do such a thing is by setting VirtualHosts on your webserver (either Apache, nginx or another...). Using htaccess for this seems quite painful.
Assuming you're using Apache, here's a useful link: http://httpd.apache.org/docs/current/vhosts/examples.html
I'm not sure why you are not using VirtualHost to set that up.
But in case you want to go the mod_rewrite way here is an useful link:
http://httpd.apache.org/docs/2.2/rewrite/vhosts.html
I hope that helps.

Have to type .php to open menu link

Our site had a link:
http://www.mechanismdigital.com/about
It previously worked fine.
Now it does not, it is required to manually type .php at the end to get to open. For example
http://www.mechanismdigital.com/about.php
and that works.
why is this?
any thoughts?
I do know it's only limited to this one menu.
Add this line of code to your .htaccess file...
redirect /about /about.php
Change about and about.php accordingly.
Put this in your .htaccess file:
redirect /about /about.php
My guess is that your server config used to have MultiViews enabled and now it does not. Re-enable it in your Apache server config and you should be good to go.
Options MultiViews
You should be able to add this to a .htaccess file if you can't directly edit the server or virtual host configuration.
Someone probably mis-edited the .htaccess file.
That file make possible the redirections, which allows to have the called "nice urls" or "clean urls"
Read the wikipedia article about it: https://en.wikipedia.org/wiki/Clean_URL
Your contact url: http://www.mechanismdigital.com/contact was also broken. (I see you just fix it)
Maybe you had an .htaccess but it was hidden, or the options set on a local php (If you can't alter the /etc/php, well, somehow you had configured the redirection, so is logical to assume an htaccess file or a local php.ini file)
Now, the methods the other answers provide actually work, but require to manually add such lino for each php.
With something like this, you can make it for each php file there:
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}\.php -f
RewriteRule ^(.*)$ $1.php

Htaccess redirect all .html pages to php get variables

My urls are currently like:
/events.html
/contact.html
What I want to do is, redirect them to a php get variable.
E.g events.html = index.php?page=events
Any ideas on how this could be accomplished?
Thanks A lot.
You are looking for mod_rewrite here.
With the rule something along the lines of (assuming mod_rewrite is installed and enabled and you're putting it in a .htaccess file)
RewriteEngine on
RewriteRule ^/(.*).html /index.php?page=$1

php URL rewrite wamp

I want to implement URL rewrite in wamp.
My ugly link is:
http://mysite.com/news.php?id=4654654&title=asdasdasdas-das-dasd-as-da-sda-d-asd-ads-as-da-sd
I want pretty URL to be
http://mysite.com/4654654/asdasdasdas-das-dasd-as-da-sda-d-asd-ads-as-da-sd
Using online generator on www.generateit.net/mod-rewrite/ for my link I get this .htaccess result:
RewriteEngine On
RewriteRule ^([^/]*)/([^/]*)$ /news.php?id=$1&title=$2 [L]
in wamp apache rewrite_module is checked, in httpd.conf I change AllowOverride None to AllowOverride All. I removed # sign from LoadModule rewrite_module modules/mod_rewrite.so
But when I click on hred with link like this http://mysite.com/4654654/asdasdasdas-das-dasd-as-da-sda-d-asd-ads-as-da-sd , I receive Not Found error The requested URL /myfolder/4654654/asdasdasdas-das-dasd-as-da-sda-d-asd-ads-as-da-sd was not found on this server
site root folder is in c:/www/myfolder
Can someone tell me what should I do to work this?
Thanks
EDIT
should I made some changes in my php file except href values?
create a new .htaccess file in your web root directory i.e c:/www/myfolder and place the code in it. and it should work.
The RewriteRule-part should start in a new line under RewriteEngine on.
There is a good beginner's guide with explanations at:
http://www.workingwith.me.uk/articles/scripting/mod_rewrite

Categories