URL Rewriting (PHP & Apache Local Server) - php

I'm using EasyPHP 14.1 DevServer and I'm currently developping my own website on my computer.
I was introduced to a new method called URL Routing/Rewriting today.
I found this useful website that generates the lines that I need to add to my httpd.conf file.
(I've double checked and the rewrite module is running)
I tried a quick example, a few ones actually, and none of them worked.
I tried to redirect myself from http://localhost/47.html to http://localhost/site1/showproducts.php?id=47 by adding these lines to httpd.conf
RewriteEngine On
RewriteRule ^([^/]*)\.html$ /site1/showproducts.php?id=$1 [L]
I wanted this link http://localhost/site1/products/47/ to lead to http://localhost/site1/showproduct.php?id=47
I'm fairly new to this, so any help would be appreciated

Ok just update that,
RewriteEngine On # Turn on the rewriting engine
RewriteBase /
RewriteRule ^products/([0-9]+)/?$ showproduct.php?id=$1 [NC,L] # Handle product requests
This will work.

Related

NAS Synology, use apache .htaccess for url-rewrite

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.

.htaccess url rewrite not passing parameter - could there be apache settings somewhere that is preventing this?

Okay, so this problem has completely stumped me and the other devs I work with. Here is the rundown:
I have a local dev environment setup with Mac Apache2 pointed at /Users/myusername/Sites/
Within /Sites I have two folders, /site-1 and /site-2, both of which have virtual hosts pointed at them site-1.dev & site-2.dev. Both site-1 and site-2 are running local installs of PerchCMS.
Within /site-2 I have an .htaccess file which I am trying to set up a URL rewrite that takes the URL /detail/slug-here and translates it into /detail.php?s=slug-here
I have tried the following rewrites (at the suggestion of PerchCMS support) and both have failed to pass the s param:
RewriteRule ^detail/([a-zA-Z0-9-/]+)$ detail.php?s=$1 [L]
RewriteRule ^site-2/detail/([a-zA-Z0-9-/]+)$ /site-2/detail.php?s=$1 [L]
Additional info:
Yes mod_rewrite is enabled in apache... in the same .htaccess file it totally works if I do a simple rewrite like this...
RewriteRule dangerzone.html index.php
One odd behavior that I've noticed is that if I remove everything from .htaccess I can still pull up detail.php by pointing my browser at /detail/test-item-1...(yes I have restarted my server) so its behaving as if there is still some sort of rewrite in place and loading detail.php sans param just as it continues to do with the rewrite in place - is this a clue that there is something off somewhere else in my server config? Note, RewriteRule dangerzone.html index.php does NOT work once it is removed from .htaccess.
Have this code in your site root .htaccess (inside /site-2/):
Options -MultiViews
RewriteEngine On
RewriteRule ^detail/([a-zA-Z0-9/-]+)/?$ detail.php?s=$1 [L,QSA,NC]
Important is to turn off MultiViews options here. Option MultiViews is used by Apache's content negotiation module that runs before mod_rewrite and makes Apache server match extensions of files. So /file can be in URL but it will serve /file.php.

Laravel 4 on PHP built-in web server (CGI) instead of Apache

I am trying to run laravel4 on a service that cannot use Apache or nginx.
everything is good till I wanted to use Routes on my project.
I've tried using /index.php/... on the URL but could not make this work.
is there any way to force laravel not to use .htaccess file or any ways to use raw PHP routing?
Try setting the "application.url" option in one of configuration files, probably in app/config/application.php or application/config/application.php:
https://github.com/laravel/laravel/blob/4cb904f44d24f856ec9c1040d2198ed8f009723b/application/config/application.php
Set it to http://127.0.0.1:54007/index.php. Now when laravel creates url it will use this as a root and the final urls should be like http://127.0.0.1:54007/index.php/account/signin.
Also you need to modify PHP Desktop settings so that it uses a fixed port. Edit settings.json file and set it like this:
"web_server": {
"listen_on": ["127.0.0.1", 54007],
In laravel's .htaccess I've found this:
<IfModule mod_rewrite.c>
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/$1 [L]
</IfModule>
So it should work fine to add "/index.php" to root url, because this is what apache's mod_rewrite does.
If something doesn't work, take a look at some other files named "url.php", "uri.php".
Let us know if that works.
EDIT.
You may also try setting root url to "index.php", without the "http://". This way it wouldn't be required to set a fixed web server port.
UPDATE
There was a bug in Mongoose web server in PHP Desktop, that prevented urls like "index.php/company/5" from working properly. See the __fix_mongoose_env_variables() php function in Issue 137 that fixes it:
https://code.google.com/p/phpdesktop/issues/detail?id=137

How do I run a CakePHP app in a sub-folder from the root domain?

I'm trying to setup a CakePHP app in a sub-folder but run it from the root domain, eg, user requests domain.co.uk and they get the webroot at {DOCUMENT_ROOT}/version-13/app/webroot.
The hosting setup doesn't allow me to change the document root so I have the following .htaccess in the root:
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteBase /
RewriteRule ^$ version-13/app/webroot/ [L]
RewriteRule (.*) version-13/app/webroot/$1 [L]
</IfModule>
This appears to do the job. However, Cake detects the sub-folder and adds it to all the URLs it creates (eg, $this->Form->create() actions, etc) so I end up with forms posted to domain.co.uk/version-13/signup instead of domain.co.uk/signup.
I know this is probably going to be something simple but I'm hitting a brick wall. No matter what I try I can't get it to work!
It's hard to understand your setup, you should explain it more. But if I got it right, check /app/Config/core.php:
Configure::write('App.fullBaseUrl', 'http://example.com');
Change your RewriteBase / to RewriteBase /version-13/ (in your .htaccess)and you should be set right up.
I had the exact same issue when I didn't have my local server set up correctly, which forced me to put my applications in a folder of my main domain.
Please note that you can have multiple apps at one core. This could be useful for you "versioning".
Ps. after a quick Google search I found the following. Didn't read it that well, but it looks like it does the same. http://cookingwithcakephp.blogspot.nl/2008/04/installing-cakephp-into-subdirectory.html

Wordpress 403 Forbidden "You don't have permission to access / on this server."

I can't access any pages/login to my WordPress based website.
I get this message:
Forbidden You don't have permission to access / on this server.
after some research on StackOverflow and other WordPress support forums I tried to change the .htacess file without success, also tried to duplicate it from the root directory to /wp-admin again nothing has changed... But I'm not really sure about what I did...
I went back to how it was when it stopped working
permissions are 705 for the folder and 604 for the .htaccess file which is :
SetEnv PHP_VER 5_3
# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>
# END WordPress
I'm using WP 3.4 and I don't know if I use PHP 5.3 (what says the .htaccess 1st line) or 4.0.1 (on PHPMyAdmin from the website host access 'OVH')
Thank you very much for your attention.
Ismaƫl
Make WP recreate the .htaccess the file itself.
Delete .htaccess via FTP, then change your permalink structure to default, then back to your desired permalink style. This will recreate the .htaccess. if that fails, you can try to reinstall the WP core by deleting everything except wp-content and wp-config.php.
Found this when looking for a similar issue I had. Cause & fix was different but may be useful to others...
I have some content external to the WordPress implementation, in a directory called "Documents" (outside the WordPress hierarchy). I then wanted a Wordpress page to list those documents so I called the page "Documents". Accessing that page gave an error. The fix was to rename the directory as "docs" (moving it to wp-content may have worked too).
If you are using WP All-in-One Security plugin, be sure to check the .htaccess file in the root of your Wordpress installation, and look for a section on whitelisted IP addresses. If your current IP is not in the list, then you will get the 403 error.

Categories