Local Apache Server mod_rewrite/pretty links issue - php

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 :).

Related

.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.

Using .htaccess to rewrite to Wordpress subdirectory?

As opposed to many questions here in StackOverflow, I'm looking for something a little different. I have a Wordpress install in a subfolder of my domain called "blog". The main part of the website is a Magento website. I'm looking to take any instance where "blog" is part of the URI, and make sure it's untouched by the myriad of other RewriteRules in Apache.
As a few examples:
http://www.example.com/blog/wp-admin/
http://www.example.com/blog/
http://www.example.com/blog/save-money-groceries-without-coupons/
...should all direct to the Wordpress site found under /blog/
http://www.example.com/
http://www.example.com/plumbing/faucets.html
http://www.example.com/about/family-history.html
...should all direct to the Magento site that is currently found under the root directory
What is the best practice in writing the .htaccess file to achieve this result?
To redirect http://www.example.com/blog/wp-admin/ to http://www.blog.example.com/wp-admin/ you can add the following to the .htaccess file
RewriteEngine On
RewriteRule ^blog/(.*)$ http://www.blog.example.com/$1 [L,R=301]
I'm not an expert on setting up Apache servers but I think you want your WordPress install in a completely different folder to Magento and then use Alias in your .conf file. You can read about the Alias directive here.
For example in my Apache .conf files I have
Alias /blog/ "/full/path/to/wordpress/htdocs/"
This way the folder /full/path/to/wordpress/htdocs/ has its own .htaccess and its own index.php - which is what you are going to want for running WordPress without jumping through hoops.
Remember to restart Apache if you update the .conf file.

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.

.htaccess not working

I have a .htaccess file to remove the index.php part of the codeigniter-style URL. It's been working fine on one computer but when I copied the file over to my laptop it doesn't seem to do anything. I'm using localhost on both machines. They both run mac osx 10.6 with the bundled apache and php and the latest version of mysql. Everything works fine, it's just the .htaccess that doesn't do what it should. Is there any setting that I might have changed on my first machine and forgotten about?!
EDIT:
I'm wondering if there is something wrong with my CI setup now. If I load the base_url ie http://localhost/~User/project/
then it loads perfectly, adding the index.php.
My config file has
$config['index_page'] = '';
However, as a test I returned this value to 'index.php'. When I loaded the base_url after this it returned: http://localhost/~User/project/index.php/index.php/controller/method
Does this suggest anything to anybody?
SOLVED:
I added a new directory command to my httpd.conf file which targeted the specific site I was working on. Seems to be happy now, but not a very satisfactory way of dealing with the problem if I have several codeigniter sites in my web root.
With just a shot in the dark do you have mod_rewrite installed on both?
If your on Ubuntu, you need to edit /etc/apache2/sites-available/default.
sudo vim /etc/apache2/sites-available/default
Where you see lines that say AllowOverride change it to say:
AllowOverride All
You may also need to enable mod rewrite:
sudo a2enmod rewrite
Then, restart the Apache server
sudo /etc/init.d/apache2 restart
Are you sure you have changed the name of the root folder?
Here is what I do:
I put this on my root folder:
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ /rootFolder/index.php/$1 [L]
and in the path you replace "rootFoldel" with the name you are using.
hope that helps!
maybe you changed the path relative to the server root. it can breaks .htaccess and may be solved with a RewriteBase /path/to/folder/ statement
edit
since the problem not seems to be this one above, you could also check the error.log file in the apache folder (probably in the logs folder). it may have your answers and it can tell you if the .htaccess is getting parsed wrong or not parsed at all.

Apache site root for development directories on localhost

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.

Categories