Mod re write breaking url - php

Update I have re- done the code and folder system of my mod re write on localhost still nothing
the link only shows like this
http://localhost/cms/member/profile.php?member=10308
my entire .htaccess file
RewriteEngine On
RewriteRule ^cms/member/([^/]*)$ /cms/member/profile.php?member=$1 [L]
when i click on the link it does nothing. if i change in the browser to
http://localhost/cms/member/10308
it says page cannot be found.
Update the problem was this peice of code causing it to not display right
<?php
if(empty($_GET['member']) || $_GET['member'] <1000 ) {
redirect(ROOT_URI);
exit;
}
?>
But i need this code.
the url will work but i need to type it in manually it wont automatically change the url

As you are using an .htaccess file which is placed under the directory "cms", you should use the following directives:
RewriteEngine On
RewriteRule ^member/([^/][0-9]*)$ member/profile.php?member=$1
This will send the request http://localhost/cms/member/(any-number) to http://localhost/cms/member/profile.php?member=(any-number)
Note:
mod_rewrite should be enabled.
In httpd.conf (or apache2.conf), replace AllowOverride None by AllowOverride All to enable .htaccess
Restart Apache server.

Related

htaccess not working on QNAP NAS

I have a QNAP NAS with Apache correctly installed. Some pages are linking fine except for ones using any RewriteRule. All other pages are linking correctly to mysql and displaying fine its the ones with any RewriteRule, these are showing up as a 404 error like this:
The requested URL /share/CACHEDEV1_DATA/Web/clients/hembury4x4/couk/view-sitemap.php was not found on this server.
URL = http://192.168.1.210/Web/clients/clientname/sitemap.html
FILE= http://192.168.1.210/Web/clients/clientname/view-sitemap.php
My rule is quite simply: RewriteRule ^sitemap.html$ view-sitemap.php [NC,L]
I have copied all the site files from my computer where the redirect was working perfectly. What do i need to add on my htaccess file?
Thanks in advance
First, apache should have rewrite module. It should present in the output of httpd -M command.
Then you should allow .htaccess files. This can be made by adding AccessFileName .htaccess directive (if it's absent) to your httpd.conf file. Also check you have this section:
<Directory />
AllowOverride All
</Directory>

Why is my .htaccess code is not working?

My htaccess file code is not working even it is right i found on many website for this each website has same code here it is :-
Options +FollowSymLinks
RewriteEngine On
RewriteRule ^products/([a-zA-Z]+)/([0-9]+)/$ index.php?action=$1&sub_cat=$2
now this thing is not working www.example.com/products/something/3/
anything else i am forgetting please help me.
Because you have a products.php file and your URL looks like www.example.com/products/something/3/, a module called "mod_negotiation" is processing the request before mod_rewrite can. The Multiviews option will allow mod_negotiation to try to "guess" what a request is for, and it sees /products/ in the URL and the file /products.php and assumes that's what the request is for, serves the request via the products.php script and mod_rewrite never gets a chance to do anything.
Solution?
Turn off multiviews:
Options -Multiviews
by adding that option anywhere in your htaccess file.

CakePHP missing controller on EC2

I have a Cake 2.3.8 app that works fine on localhost and I uploaded it to an Ubuntu 12.04 EC2 instance, but on the index/home file I'm getting a "Missing Controller" error.
The CSS, header and footer load fine on the home/index page, but it can't seem to find the controller. Every single other page/controller of my app won't even load, I get a 404 error.
I tried this but my issue still persists.
What else should I look for that would cause it to not find the controller and not even load any other pages?
Update
I moved my contents to /var/www so it would be accessed through my-ec2-instance.com. When I go to my-ec2-instance.com/index.php the page displays (which is PagesController/home.ctp). However, anything else gives a 404 error. Modrewrite is also enabled
I can also access my actions when I reference index.php, although it displays in mobile format for whatever reason (I have a responsive template). Ex: www.my-ec2-instance.com/index.php/users/login works, although it's in a mobile format
www.my-ec2-instance.com/index.php //works
www.my-ec2-instance.com/index.php/users/login //works, but mobile format
www.my-ec2-instance.com/users/login //404 error
Please connect your instance via putty then press
sudo nano /etc/httpd/conf/httpd.conf
Check the given below line and remove the # tag
LoadModule rewrite_module modules/mod_rewrite.so
After that you can replace:
AllowOverride None
with
AllowOverride All
Note: AllowOverride None -> AllowOverride All.
From Crtl+X then press Y then press Enter (you can use this command according to your OS)
After that you can execute the command in putty
sudo service httpd restart
Then check your .htaccess file (please make sure your .htaccess should be correct) for cakePHP .htaccess
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteRule ^$ app/webroot/ [L]
RewriteRule (.*) app/webroot/$1 [L]
</IfModule>
Sounds like an issue with your .htaccess file which is what would properly rewrite short URLs & handling controller routing.

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

MOD REWRITE working in local host but not in server

First of all , I clarified with my hosting company and they have verified that Allow Override setting is enabled.
Second if I write garbage value in .htaccess file, then I get "Internal Server Error" which further proves that .htaccess is not skipped.
I am trying to do this
Input : all/3
output: all.php?id=3
I wrote following in .htaccess file, which I copied from a tutorial site.
# Enable Rewriting
RewriteEngine on
# Rewrite user URLs
# Input: user/NAME/
# Output: user.php?id=NAME
RewriteRule ^all/(\w+)/?$ all.php?id=$1
all.php file
<?php
echo $_GET['id'];
?>
Now if I enter localhost/all/3 then I get 3 displayed.
If i enter www.mydomain.com/all/3 then the page is blank.
Also I have only the above code in .htaccess file and nothing more or less. So why I am getting different behaviour in localhost and in my server?
try this :
RewriteRule ^all/(.*)$ all.php?id=$1
Sounds like your host has enabled the MultiViews option. Solutions are to get them to disable it or probably a quicker option, rename your PHP file to be something other than all.php, just so long as the basename (minus the extension) does not match your RewriteRule pattern.

Categories