Hello I would like to change the url generated with php my website. I've tried with .htaccess but does absolutely nothing, I do not know if I'm doing something wrong.
Right now I do not have to test server, I can only do so locally. I have installed WAMP but including the .htaccess file in the folder www does nothing, URLs continue with php variables as usual.
I have enabled mod_rewrite in wampserver. By including text meaningless in the .htaccess file fails to access by browser to localhost, that is I think the .htaccess is working.
Htaccess I have written in this way for me to rewrite the url:
RewriteEngine on
RewriteRule ^(.*)/(.*)/(.*)$ /novedades/novedades.php?id=$1&url=$2&url=$3
#http://localhost/novedades/novedades.php?id=2&url=tren&url=tren
#http://localhost/novedades/tren/tren.php
I do not know if I'm doing something wrong, to see if I can lend a hand.
Related
I try to making work a php site on my NAS Synolgy DS916Play.
The problem I have is I need to rewrite all api call to index.php with in form:
Initial call: controller/action?queryParams final call:
api/index.php?route=controller/action&queryParams;
I try to put a .htaccess in site folder, but Apache didn't read this file (I put something wrong there, and no error occurred).
SO I need help in two problem:
Configure Apache on NAS, to read .htaccess,
A .htaccess file for what I need.
I have a version, but I'm not sure if it's correct:
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^([\w\/\-]+)/?$ api/index.php?_route_=$1 [QSA]
</IfModule>
Or if someone has other solution, I'm glad to hear it.
The site is One page application angularJS with backend php.
I tried .htaccess on my local server (localhost) and it's working well.
But when upload this code to life server not working ... i don't know why ?!!
This is the content of .htaccess file
RewriteEngine On # Turn on the rewriting engine
RewriteRule ^home/([A-Za-z0-9-]+)/([A-Za-z0-9-]+)/([0-9]+)/?$ home.php?country=$1&name=$2&listingId=$3 [NC,L]
the expected that url work ... it's work on localhost only ... but on live server it's give me 404 notFound
MY-DOMAIN.COM/home/USA/David/1234
My live server is www.000webhost.com
have you tried to follow the advice given by your hoster and put RewriteBase / at the top of the .htaccess file?
see http://www.000webhost.com/faq.php?ID=16
I have this .htaccess on my Windows dev machine and everything works fine
RewriteEngine On
RewriteRule ^(.+[^/])/$ http://%{HTTP_HOST}/webserv/$1 [R=301,L]
RewriteRule ^login/([0-9]+)/([0-9]+)$ login.php?par1=$1&par2=$2 [L,NC,QSA]
When I upload it on my Centos server I get the error
404 The requested URL path_to_script/login.php was not found on this server.
I cannot understand why this is. The file is definitely there and I gave permissions 777.
I have checked if the .htaccess is actually used by adding rubbish in it and getting an internal error (500) which means that it is working.
Also when I use .htaccess to make restrictions on IPs that have access to the directory it works. mod_rewrite is loaded as shown in the phpinfo() I have tried.
I am at a loss here.
EDIT
I noticed that it tries to search in the base_path appending it to the root path e.g.
/path_to_script/path_to_script/login.php
And that is why it fails. How do I solve this?
I finally solved it but in a way that I am not sure I like. At least it works. If someone has a better solution I would be glad to see it.
RewriteRule ^login/([0-9]+)/([0-9]+)$ http://host/webserv/login.php?par1=$1&par2=$2
The reason I don't like this solution is because I does not give a pretty url. It just redirects.
I still do not understand why I get the root directory appended to the request if I instead write:
RewriteRule ^login/([0-9]+)/([0-9]+)$ login.php?par1=$1&par2=$2
Im aware this is a question asked a lot and i have viewed them all trying so many different variations but it wont work and i dont know what im doing wrong.
I created a .htaccess file a long time ago in order for it to point to my 404 error page which is has done fine for me but i want to rewrite the urls on my site now as there are a lot of posts and its getting messy with all the variables in the url.
i have a page called viewpost.php which gets passed 1 variable (there are other pages aswell but this is for the example) viewpost gets passed 1 variable so it becomes /viewpost.php?ID=10
RewriteEngine on
RewriteRule viewpost-ID-(.*)\.htm$ viewpost.php?ID=$1
i added these 2 lines to the htaccess file. i tried removing the 404 code form the file and saved it but it didnt make it work either. Is there something else i need to be doing other than adding this code to the .htaccess file?
the site is currently being hosted on atspace
Hosting OS Proprietary *nix
Perl version 5.8.4
MySQL version 5.1
Perl path /usr/bin/perl
Sendmail path /usr/local/bin/sendmail
CGI-BIN path not required (You can run CGI, Perl scripts from any domain/subdomain folder)
Perl Modules 2900+ installed modules (Click here to view the full list)
PHP Version 5.2.17 Change
PHP.INI Edit
PHP Info [View PHP5.2.17 Info] [View PHP5.3.6 Info]
Directory Protection Enabled
this is what is written on the hosting settings page. im not sure whats required for the to be able to rewrite a url but since the .htaccess file is currently working for my 404 page im assuming its set up fine?
Maybe some other rules in the .htaccess file are overriding your rule or you could be having a case-sensitive issue. Add [NC,QSA,L] at the end of the RewriteRule line.
RewriteEngine On
RewriteRule viewpost-ID-(.*)\.htm /viewpost.php?ID=$1 [NC,QSA,L]
NC ignores the case, QSA appends any extra query string parameters to the destination URL and L tells Apache to stop processing more RewriteRule entries if this is matched for the current URL.
I think I'm missing something and don't think I really understand how rewriteBase works.
The problem I have is that I have a production site where the site is in the root directory yet I have my development site in a localhost subdirectory. Eg http://www.sitename.com/ vs http://localhost/sitename/
If I have for example an images folder I want to reference the images from the site root by using the initial slash in the href. Eg Using a relative href (without the initial slash) is not an option. This will work on the production site but the development site is looking for http://localhost/images/imagename.jpg instead of http://localhost/sitename/images/imagename.jpg
So I thought all I needed to do was setup the following in my .htaccess file to force the site root to my subdomain within the development environment:
Options +FollowSymLinks
RewriteEngine On
RewriteBase /sitename
But this still uses localhost as the site root instead of localhost/sitename.
Can anyone please give me some pointers?
-------------------------EDIT---------------------------
I stopped trying to do this in the .htaccess file and tried to just use the html command but this also didn't work.
In the end I set up Virtual Hosts in Apache on the local server but it seems like such an awful lot of overkill to just change the site root. I'm also concerned that other developers on the LAN network won't be able to access the site properly via the virtual host.
I'm really needing some 'best practice' advice please on setting up a workable development environment in WAMP.
RewriteBase alone, basically, tells Apache where to apply the RewriteRules. Here you don't have any. By the way, you can either remove the RewriteBase directive altogether, or change it to:
RewriteBase /
The following two lines should get it to work for your development environment only:
RewriteCond %{ REQUEST_FILENAME } !-f
RewriteRule ^(.+)$ /sitename/$1 [L,QSA]
These two directives mean: "if the requested file does not exist (-f), and only in that case, rewrite the url prepending /sitename/ to the requested URI ($1)".
For more info you can have a look at Apache mod_rewrite docs and Apache URL rewriting guide.