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.
Related
I am new in creating a website using wordpress. I am using xampp to create a local wordpress website and my website run under: localhost/mysite. I want to import my local website to my live website https://vsaftest.wordpress.com/ by going to the setting of my local website and then changed the wordpress Address and site address from http://localhost/mysite to https://vsaftest.wordpress.com/. After that then I can not access to my local site using http://localhost/mysite anymore, and inside the website https://vsaftest.wordpress.com/ there is nothing there also. I know that I made a mistake here but then anyone can help me how can I change back so that I can access my site from localhost :(
I've never used Wordpress before, but going purely from your desription, you seem to think that changing a setting on and for your local machine will somehow affect the settings on a remote machine.
and inside the website https://vsaftest.wordpress.com/ there is nothing there also
But was there nothing there beforehand either? In other words; Nothing's changed?
I think the reason you cannot view your local site anymore is precisely because you made the change you said you did. Instead of its changing the remote machine (which it probably doesn't do...I don't do WP dev, so I don't know for sure) it changed your local machine.
Can you not just change wordpress Address and site address on your local site back to what it was before?
There are many pitfalls one might encounter when moving a Wordpress website from a local development environment to production. Here are the main things to remember and look out for.
Htaccess
When developing in Xampp it's very common to include the website's directory name in the .htaccess' RewriteBase and RewriteRule. Assuming your production website will be situated in the root directory you'll want to remove the directory references from your .htaccess file.
For example your development .htaccess file might look like this:
# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /mysite.com/
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /mysite.com/index.php [L]
</IfModule>
# END WordPress
But in production you'll need to adjust it to look like this:
# 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
One good development practice you can adopt is creating .live and .dev htaccess files. Create .htaccess.dev and .htaccess.live files and store your development and production htaccess data in them respectively. Your real .htaccess file will then contain the current active data and you can easily copy/paste from the .dev and .live files to it if needed.
Database
When you move a Wordpress website to production you must also create a production database for it. Make sure the database created has the same collation as the development one and that the database credentials in your wp-config.php file are updated to reflect the production database user, password, etc. Remember that if your WP_DEBUG variable is not set to true database errors will not be shown if a database connection error occurred in your production website. Because of that database errors in production more often than not lead to a "white screen of death".
Another thing one must make sure (and you already mentioned in your question) is that the siteurl and homeurl keys in your wp_options table are updated to reflect the production website url. In case multiple domains exist (for example .com and .co) one can enforce the correct url by defining the WP_SITEURL and WP_HOMEURL constants dynamically within the wp-config.php file.
PHP version
Last but not least, make sure the PHP version required for your website is compatible with the production server's PHP version. 2017 is a transitional year in terms of PHP support. Whereas Xampp already supports PHP 7 sadly many servers still do not.
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.
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
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've had to move from testing on the live server, to testing locally on a virtual apache server. I've installed XAMPP just fine, downloaded and installed the wordpress files and the database. Everything looks great! The local version of my homepage is identical to the live version. There's only one problem: the homepage is the only page that works. When I click on one of the links i.e. the "about" page (http://localhost/wordpress/about/), I am redirected to the xampp control panel (http://localhost/xampp).
I have a good feeling this has to do with a problem with the "pretty links"/mod_rewrite rules. I made sure I brought over the .htaccess file, and it contains the rewrite instructions. The wordpress database has the proper permalink structure, and the httpd.conf file has the "RewriteEngine on" and the "FollowSymLinks" directives enabled. There has got to be some sort of rewrite problem here, although I am not ruling out something else stupid I might have done. Thanks for all your help!
-E
*Here is what the .htaccess looks like:
# BEGIN WordPress
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
# END WordPress
In the httpd.conf, change the
DocumentRoot "/path/to/your/app/wordpress"
also
# This should be changed to whatever you set DocumentRoot to.
#
<Directory "/path/to/your/app/wordpress">
This should work, the path is absolute.
And do you have load the:
LoadModule rewrite_module modules/mod_rewrite.so
in httpd.conf??
If your server version works with a domain name, i.e: http://domainname.com is equivalent that http://localhost/wordpress the rewrite rules will be differents. post the rules here.
The problem is that wordpress does not believe in relative paths for some reason. There is an assumption that wordpress is running from the server root not a directory under the root (e.g. /var/www/wordpress will not work, but /var/www/ will).
The problem is with the .htaccess file they provide. It should re-write it to index.php and not /index.php. Change that line in your config and it will work.
What happens is that it tries to actually go to the default document root (in my case /var/www/index.php, which does not exist since I am using http://localhost/worpress which is an alias for ~/projects/worpress). You can check your error log and it will tell you where it is trying to look for the index.php file (which will return a 404 error).
I can go on a rant about how stupid it is that they do that and how bad the whole software design of wordpress is. But I will spare you that :).