.htaccess mod rewrite and MAMP - php

having issues with what i think is linked to the mod rewrite in mamp.
The rewrite works fine on the live server, but im working locally with MAMP and getting issues.
The problem is linked to this:
I rewrite the following URL:
http://localhost/BuildSanctuary-Dev/viewbuild/64/three-fiddy-z/1
That should rewrite as:
http://localhost/BuildSanctuary-Dev/viewbuild.php?id=64&title=three-fiddy-z&page=1
The issue is that i get a 404 for page not found.
The requested URL /viewbuild.php was not found on this server.
Which it clearly is... but if i visit just /viewbuild.php it works fine.
The rewrite in the .htaccess is:
RewriteRule ^viewbuild/([a-zA-Z0-9_-]+)/([a-zA-Z0-9_-]+)/([a-zA-Z0-9_-]+)/?$ /viewbuild.php?id=$1&title=$2&page=$3 [L,QSA]
Any ideas? I have done the research and everything in the apache conf is showing as Allowing All...
Thanks.

Your rewriterule redirects to /viewbuild.php and not /BuildSanctuary-Dev/viewbuild.php:
RewriteRule ^viewbuild/([a-zA-Z0-9_-]+)/([a-zA-Z0-9_-]+)/([a-zA-Z0-9_-]+)/?$ /BuildSanctuary-Dev/viewbuild.php?id=$1&title=$2&page=$3 [L,QSA]
A mabye better variant would be to put the .htaccess into the /BuildSanctuary-Dev/ folder and use a relative path as redirect:
RewriteBase /BuildSanctuary-Dev
RewriteRule ^viewbuild/([a-zA-Z0-9_-]+)/([a-zA-Z0-9_-]+)/([a-zA-Z0-9_-]+)/?$ viewbuild.php?id=$1&title=$2&page=$3 [L,QSA]

Related

I have problem in .htaccess in my localhost not redirecting correctly

My .htaccess file contains:
Options +FollowSymlinks
RewriteEngine On
RewriteRule projects$ projects.php
RewriteRule projects/$ projects.php
RewriteRule projects/page/([^/]*)$ projects.php?page=$1
RewriteRule projects/page/([^/]*)/$ projects.php?page=$1
RewriteRule projects/company/([^/]*)/$ projects.php?companyid=$1
RewriteRule projects/company/([^/]*)$ projects.php?companyid=$1
RewriteRule projects/([^/]*)$ projects.php?id=$1 [L]
It was working fine, but suddenly this section is not working in my website.
This should redirect to "projects.php?companyid=$firstvariable",
but actually, I don't know why.
I tried restarting my PC and deleting temp and restarting WAMP.
After some interactive troubleshooting with OP, it appears that WAMP's Apache/PHP will execute a PHP file that matches the directory portion of the URL path if it exists, before applying the .htaccess RewriteRules.
In other words, if you have a file named Abc.php, and you request /Abc/def, WAMP's Apache/PHP will just execute Abc.php and not consult the .htaccess file.
I'm not sure if this is something special about WAMP and whether it's out-of-the-box behavior. I can't find any documentation on being able to control/change this behavior.

PHP Clean URLs not working as intended

I am trying to use a .htaccess file to change my URLs from
xxx/table/change.php?id=1
to
xxx/table/change/1
I have the following code in my .htaccess file, which is in the root folder of my web site.
RewriteEngine On
RewriteRule ^change/([^/\.]+)/?$ change.php?id=$1 [L]
RewriteRule ^change/([^/\.]+)/?$ change.php?id=$1 [L]
However when I restart Apache and visit the desired URL, it still shows up as
xxx/table/change.php?id=1
Any suggestions?
mod_rewrite is uncommented in the httpd.conf file.
how about you use
change/(\d+)$ change.php?id=$1 [L]
that is when you visit
xxx/table/change/1
you are not redirected or 404, you get the correct page. is that what you are looking for?

Apache mod rewrite not working on mac os x lion

I'm trying to set up mod rewrite on os x and it doesn't seem to be working properly.
I've edited my httpd.conf file to include the module, I've changed the AllowOverride setting to "all" in both my httpd.conf and my user.conf file.
Now when I add a htaccess file with the following:
RewriteEngine on
RewriteRule ^$ public/ [L]
RewriteRule (.*) public/$1 [L]
I get a 404 not found saying ...
"The requested URL /Users/matt/Sites/framework/public/ was not found on this server."
Even though that folder does exist.
The fact that it's redirecting would suggest that mod rewrite is installed and working, but I'm not sure why I'm getting a 404. Any one else had this problem?
Thanks
I did test your rewrite rule on a Windows machine and it thrown Internal server error. I tweaked it a little bit and came to this solution and it seems to work just fine on my test environment.
Could you give it a try and see if it's ok for you?
RewriteEngine on
RewriteRule ^public/ - [L]
RewriteRule .* public/$0 [L]

Rewrite rule in WAMP

I am using a WAMP Server. I need to apply rewrite rule for the pages in my local system. I have enabled the rewrite_rule from the WAMP icon at Task bar.
My Website path in local system is http://localhost/Kitty_Enfin/.
http://localhost/Test/index.php -> http://localhost/Test/home
http://localhost/Test/index.php?do=main -> http://localhost/Test/main
http://localhost/Test/index.php?do=profile&uid=1 -> http://localhost/Test/profile/1
Above are the pages I need to rewrite.
My question is: where I need to place the .htaccess file?
Whether in www/ or www/Test
What is the .htaccess Rewrite rule for the above
It will be more helpful if anyone helps on the Following issue.
Thank you for your reply. When I used the above it not worked for me. But I used another rewrite rule which works for the first two:
RewriteRule ^([^/\.]+)/?$ /\Test/\index\.php [L] - Working
(http://localhost/Test, http://localhost/Test/index)
RewriteRule ^([^/\.]+)/?$ /\Test/\index.php?do=$1 [L] - Working
(http://localhost/Test/main)
RewriteRule ^profile/([^/\.]+)?$ /\Test/\index.php?do=profile&uid=$1 - Working but the CSS and other scripts are not work here.
And also the links in the pages are http://localhost/Test/profile/ instead of http://localhost/Test/.
Do you have any idea on this issue? Please correct me if I did anything wrong.
Do you have any idea on this issue. Please correct me any thing i did wrong
Thanks
RewriteRule ^/?index.php home/
RewriteRule ^/?index.php?do=(\w*) $1/
RewriteRule ^/?index.php?do=(\w*)&uid=(\w*) $1/$2
place the .htaccess in "Test" folder
I can only answer this from your clue

Clean URLs don’t work after upgrade

I recently upgraded my CodeIgniter app from v1.7.2 to 2.0.2.
I use mod_rewrite to produce clean URLs without index.php e.g. example.com/controller/action. It is working on my local dev server but when I updated my production app all requests to example.com/controller/action result in displaying main page (i.e. index.php).
When I access address like that: example.com/index.php/controller/action it works.
Mod_rewrite is on as it was working fine with previous code version. With 1.7.2 I used $config['uri_protocol'] = "AUTO" but now I switched to "PATH_INFO" because auto resulted in 404.
Because it is working on dev I’m wondering if I missed any deployment step. Any ideas?
There are .htaccess rules I'm using with CI 2:
Options +FollowSymLinks
RewriteEngine On
RewriteBase /
<IfModule mod_rewrite.c>
#paths that you don't want to rewrite
RewriteCond $1 !^(index\.php|assets|session|robots\.txt)
RewriteRule ^(.*)$ /index.php/$1 [L]
</IfModule>
I think I had some similar problem and I believe it got resolved by changing permission on my root folder to 777... but that was on XAMPP

Categories