Rewrite Rules Not Working in MAMP Pro Development Environment for Production Images - .htaccess

When working on a project, I would like to use the online images, so I don't have to download e.g. all images (as described here).
To achieve this, I wrote a view lines in my .htaccess-file:
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteCond %{SERVER_PORT} 8890
RewriteRule ^wp/media/.+ https://www.example.com:443%{REQUEST_URI}
</IfModule>
According to htaccess.madewithlove.be this should convert an image url from:
https://example.localhost:8890/wp/media/27442.jpg
to:
https://www.example.com/wp/media/27442.jpg
Context:
MacBook Pro
OS X Catalina 10.15.2
MAMP Pro 5.5.1
WordPress 5.3.2
example.localhost:8890 (SSL) up and running
local website is working fine
What I already tried/verified/adjusted:
How to get htaccess to work on MAMP
mamp pro htaccess rewriteRule not working
https://wordpress.stackexchange.com/questions/346778/rewrite-rule-to-load-images-from-production-does-nothing?rq=1
The .htaccess is being executed. When entering garbage, I got a error 500
Changed httpd.conf accordingly
Am I missing something? What else could prevent this from working?

The problem was that I had another .htaccess-file inside the wp-folder, because I moved the WordPress installation into its own directory (see here). When moving the rules into this inner .htaccess-file, it started working immediately.

Related

Migrating CodeIgniter from WAMP to Ubuntu 12.04 LTS LAMP

After I successfully installed Ubuntu 12.04 LTS LAMP on my local machine, following this TUT. And installed phpmyadmin with this instruction. I migrated my working CodeIgniter project inside /var/www/ and updated my database. Everything seems to be working fine except i'm having a 404 error saying:
GET http://192.168.1.11/quantum/login/ 404 (Not Found)
The following error occured: error Not Found
GET http://192.168.1.11/quantum/user/ 404 (Not Found)
The following error occured: error Not Found
After hours of desperate troubleshooting I found some possible causes.
.htaccess (already updated)
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule .* index.php/$0 [PT,L]
mod_rewrite (already enabled)
but still, i cant seem to make it work. any ideas? is there more to be configured to make the project running?
(dumb) Have you checked all folders have successfully been copied?
Have you changed your base_url in the config file? (/application/config/config.php)
When mod_rewrite is enabled (to remove the index.php in the URL), your index_page item in the config file must be blank.
If you have already checked these things, try disabling mod_rewrite in order to track if this is your issue.
Turns out I forgot to reconfigure my htaccess by allowing override on my httpd.conf inside apache2.
<Directory /var/www/quantum>
AllowOverride All
</Directory>
Works like peanut butter and jelly.

modrewrite on cshtml files are ignored by mod_mono

I've got mod_mono and mono installed on my webserver and I'm trying to get this simple modrewrite working, however it seems to be ignored by mod mono.
RewriteEngine on
RewriteRule ^Projects/page1.cshtml$ /project2 [PT]
I have that in my .htaccess in the document root. If I use any other extension besides .cshtml, it works as intended. Any ideas?

.htaccess file 404 error with parallel plesk server

I have my .htaccess file working in localhost. But its not working if i upload it in server. It throws me 404 error.
I am using Parallel Plesk 11.0.9 and i can't find conf file for the same on that. If anyone has any idea how to fix it or any workaround for url rewriting would be great help.
Anyway here's the code in htaccess:
RewriteEngine on
RewriteRule ^store/living/Hutches-Armoires-Side-tables-Coffee-tables-Entertainment-centers? store.php?store=Living
RewriteRule ^store/dining/sideboards-buffets-chairs-benches-Dining-table$ store.php?store=Dining
RewriteRule ^store/working/Bookshelves-Study-tables$ store.php?store=Working
RewriteRule ^store/accessories/Boxes-Photo-Frames-Mirror-Frames-Block-Stamps-and-Book-stands$ store.php?store=Accessories
RewriteRule ^store/hallway/Console-tables-Armoires$ store.php?store=Hallway
RewriteRule ^store/sleeping/Bed-Frames-Night-Stands-Dressers-Mirror-framesBed-Linens-Canopies-Curtains$ store.php?store=Sleeping
You may need to wrap your rewrite rules with:
<IfModule mod_rewrite.c>
...
</IfModule>
...probably a good idea anyway.
Or you could try putting your rules into a vhost.conf file in the conf directory immediately below the location of your httpdocs directory. For example on a Centos machine the web root might be
/var/www/vhosts/domain.com/httpdocs
and you should have a:
/var/www/vhosts/domain.com/conf
directory, this will contain a set of pregenerated Apache config files that Plesk creates. If there isn't already create a vhost.conf and add your rules between a set of
<Directory /var/www/vhosts/domain.com/httpdocs/ >
... your rules ...
</Directory>
Once you've created the vhost.conf file you will need to tell plesk about it with
/usr/local/psa/admin/sbin/httpdmng --reconfigure-domain domain.com
If you still can't get it to work you can add a log for mod_rewrite, see this relevant SO answer for details
Is your Plesk running IIS and supporting PHP via FastCGI or ISAPI? If that is the case, check whether URL Rewrite is installed and follow this guide to translate htaccess (for apache) into web.config (for IIS)

htaccess rewrite working offline on WAMP but not online on linux host

I'm just going to explain my problem here :
http://mysite.com/movie/20000
should be rewritten to
http://mysite.com/movie.php?id=20000
my htaccess file :
Options +FollowSymlinks
RewriteEngine On
RewriteRule ^movie/([0-9]+)$ movie.php?id=$1
On my localhost WAMP installation this works fine, but when I put it online on my linux host it doesn't completely work. It does go to the movie.php page, but it seems it gives no GET parameter id.
Edit :
if I use
Options +FollowSymlinks
RewriteEngine On
RewriteRule ^movie([0-9]+)$ movie.php?id=$1
then
http://mysite.com/movie20000
Goes to the correct page, but I would like /movie/20000 and not just /movie20000
It also seems that my host automatically rewrites a visit to mysite.com/movie to mysite.com/movie.php
After searching for a long time, and pulling some of my lovely hair out I found the solution.
I just added
Options -MultiViews
to my htaccess file and that fixed it.
Why? Because .php was being added to urls without an extension, which I really did not need.
This should work.
RewriteRule ^movie/([0-9]+)$ http://mysite.com/movie.php?id=$1 [NC,L]
Don't forget the [NC, L] it means Case insensitive, last rule... If you don't, it will continue to process through your htaccess rules, maybe triggering other ones.
Still, the stuff below is good advice.... :)
Check to see if the Rewrite module is loading with apache. Look for this line in the httpd.conf file:
LoadModule rewrite_module modules/mod_rewrite.so
Check to see if your apache config allows for .htaccess files for your system or in the virtual host definition.
Also, test with a simpler rewrite catch all and test that alone to see if it's working at all like this (get rid of everything else in your htaccess file to limit the test):
RewriteEngine On
RewriteRule ^(.*)$ http://www.google.com [L,R=301]
Any request to your site should go to google if the configuration for apache is correctly set.

.htaccess not working on my server

I'm working on my project and now I want to transfer it from my localhost to server. Everything seems to work fine, but .htaccess doesn't work.
The server should be suporting mod_rewrite and print_r(apache_get_modules()); shows mod_rewrite running.
But still, when I type myaddress.com/contact, it shows error 404.
Here is the .htaccess file, but it should be fine, since it runs on my localhost:
RewriteEngine on
RewriteRule ^adminator/?$ adminator/login.php [L]
RewriteRule ^([^/\.]+)/([^/\.]+)/?$ index.php?page=$1&detail=$2 [L]
RewriteRule ^([^/\.]+)/?$ index.php?page=$1 [L]
Do you have any idea?
Thanks, Mike.
Does the server allow .htaccess? It doesn't really have to.
Try other directives, ask your hosting provider, or check the configuration yourself if possible.
I tried testing your rules they should be fine on urls such as: http://myhost.com/test1 and http://myhost.com/test1/test2 result in requesting url: index.php?page=test1 and index.php?page=test1&detail=test2
So the problem is not your rules, it is your server setup somewhere. As Mewp said check your Apache config file, look for AllowOverride which should be enabled for .htaccess files to overriding default settings.
Ok, fixed it .. deep in the hostings settings, there was an option to activate it .. but I found it after 4 hours of looking around .. :P

Resources