I have this .htaccess rewrite rule in my Live environment: RewriteRule ^./-v. /Dev1/index.php [L]
and this one in my local (Laragon) dev environment: RewriteRule ^./-v. /index.php [L] i.e. they rewrite to my index.php where I interrogate the URL. They are identical other than my root directory in dev is /Dev1/ (and just / in live).
In index.php I use $_SERVER['REQUEST_URI'] to examine the 'freindly' incoming URL (which may have come from a search engine) e.g. www.mysite.com/thingA/subthingB/-v.
In the live environment it works correctly, i.e. $_SERVER['REQUEST_URI'] gives /thingA/subthingB/-v but the development environment just gives /Dev1/. The local dev environment uses Laragon on my PC.
Obviously I want to keep my dev and live code as identical as possible - any idea why the difference?
Thanks for any help.
My solution ...
I didn't really get to the bottom of the problem - it seemed to be intermittent depending on the test data, and there seemed to be other strange things going on.
I have solved it by making 'localhost/dev1' my root directory in Laragon rather than 'localhost' - I hadn't realised how easy this was to do in Laragon. This will also help me tidy up a few other things.
Related
I'm using Jekyll and I'm on my dev stage where I want to test the whole website on XAMPP. The problem is that Jekyll generates relative URLs showing to the root. But in XAMPP (Apache Webserver) the webpage doesn't work because CSS, JS, images are not in root.
Example of generated HTML:
<img src="/assets/img/logo.png">
So Apache is searching assets/img/ in root, but everything is in a subfolder in dev env.
The URL of the HTML site on my development environment is http://localhost/k.dev/k.dev/_site/kontakt.php. There is no problem on production with Apache webserver because the website will be in webroot.
How can I handle this problem for dev and prod environment with .htaccess? Maybe with a system variable? And how can I fix the URLs now?
RewriteEngine on
# Development
RewriteCond %{ENV:ENVIRONMENT} = dev
# RewriteRule or Redirect? Add prefix /subfolder/subfolder/ to all links like /page1.html, /page2.html, /assets/, /inc/ etc.
Thank you very much.
EDIT:
I created a VirtualHost in XAMPP Apache Webserver. The documentroot is the subfolder now. Thanks to #brombeer.
This may seem a dumb question, I need my symfony 3 app to behave different in production than it does in my local machine. I know there is an entry point for each env, app.php and app_dev.php
I don't want to change the application web/.htaccess file because it's followed by git, I was expecting an 'env' var or something similar in app/config.yml but there is also a config.yml and a config_dev.yml, so it has to be another place where I can define if I am working with prod or dev env.
Documentation says that I need to setup my apache server to use either web/app.php or web/app_dev.php, and this is my question. I'm using apache 2.4 and I tried using the following directive:
<VirtualHost *:8000>
<directory>
...
DirectoryIndex app_dev.php
</directory>
</VirtualHost>
I restarted apache, but when I type localhost:8000 in my browser, it keeps using the default app.php, I need my apache server to use app_dev.php, I don't want to use the built-in server because it gets buggy after a while.
Can anyone please help me with the apache configuration to use the dev env?
I think you have the following problems: regardless of which DirectoryIndex you define, the server also picks ups some settings from .htaccess. Could it be possible that you have another reference to app.php in there, like RewriteRule ^(.*)$ app.php [QSA,L]?
Then you could do the following: move that exact setting from .htaccess to your server configuration, both locally and on the production server. Then you can keep all other settings independent from your enviroment.
If this does not help yet, please share the content of .htaccess.
Another way of solving could be to use a recent Symfony version and put everything that might change between environments in the .env file. Don't put it under version control, as this file might contain sensitive information. Then have a look at the current basics: you no longer have a app.php and app_dev.php, as the changes were only little. A common index.php is used, and it reads all current settings from .env
I am experiencing a strange issue regarding displaying symbolic links. I have copied existing working code from my development environment, to a test environment. Looking at the code it should work. This makes me think that the issue might be elsewhere but I do not know where to look.
I am using Apache 2.2 on a CentOs 5.8 machine
All files and folders under document root including root folder is owned by apache
This are the lines of code in the vhost file
RewriteEngine On
RewriteCond %{DOCUMENT_ROOT}/$1.php -f
RewriteRule ^([a-zA-Z0-9_-]+)/?$ /$1.php [QSA]
When I go to http://example.com/home
I get this error in the error log:
File does not exist: /var/www/my_document_root_folder/home
If I add .php to the URL it works:
http://example.com/home.php
The exact same RewriteRule works fine in my development environment. Could the issue be somewhere else and not in the actual RewriteRule?
I copied my development vhost file to this test environment. I only changed the ServerName, DocumentRoot, ErrorLog paths etc.
Any help is much appreciated, it's driving me bonkers.
-M
I have answered my own question. It turns out that I made a spelling error on one of the the paths. Once I fixed that everything works fine. Feeling a bit stupid right now :(
-M
I have 3 servers, a localhost apache server, a testing remote server and the production live server.
I have the same installation of codeigniter and site set-up on all 3 of them and on the localhost and testing servers routing without 'index.php' works 100%. On the Production server however, no matter what the URL says only the homepage (via the default controller) will be shown, it seems all routing rules are being ignored except the default one.
If however index.php is added in the URL then it will work like it supposed to.
For instance if the URL on the production site is: 'www.mysite.com/information' then the content that loads is form the default controller.
But when the URL on the production site is: 'www.mysite.com/index.php/information' then the content that loads is from the 'information' controller.
This is the contents of my htacess file: http://pastebin.com/cDaZVJ8A
This is my routes config file: http://pastebin.com/7Ewc2bwN
My $config['index_page'] is set to nothing.
I really dont know why its not working, the same setup on all servers in term of codeigniter itself, and mod_rewrite IS working on the production server.
I don't know what to do, how can I find-out what's wrong?
This is quite a common problem that often occurs when people move a codeigniter install from one environment to another. I have no idea why it occurs, could be a difference in server OS or apache settings, but the solution is often to add a question mark ? to the RewriteRule for the index.php in your .htaccess file.
Old:
RewriteRule ^(.*)$ index.php/$1 [L]
New:
RewriteRule ^(.*)$ index.php?/$1 [L]
Check your Apache virtual host configuration and verify that you have AllowOverride All in your directory definition.
Maybe something is wrong with your .htaccess file?
Once I had problem when I moved application to production server, because RewriteBase was set to some directory on development server.
On my production server application was in web root directory, so RewriteBase should be /, and i had /something there.
Once i had silly problem with upper/lowercases, when i moved site from development server (windows) to production (linux).
I had the same problem. I was using function to convert article names to URL's (slugify).
On localhost and on server this function returned slightly different urls.
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.