Forum Moderators: phranque

Message Too Old, No Replies

Rewriting URLs not working after moving to subfolder

         

jancek

11:02 am on Aug 18, 2011 (gmt 0)

10+ Year Member



Hello,

I have my Wordpress site moved to subfolder on my server (Windows server with WAMP). Now it is placed in localhost/folder/.

I have changed the htaccess file from

<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>

to

...
RewriteRule . /folder/index.php [L]

The rewriting is not working anymore. Basic URLs with parameters (?p=123) are working, neither do the nice.

Can somebody help me? I have already tried to change AllowOverride set to all in httpd.conf, without success.

lucy24

4:40 pm on Aug 18, 2011 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



Basic URLs with parameters (?p=123) are working, neither do the nice.

I can't get this sentence to work. Is there a missing "not", a superfluous n, or did your cat walk across the keyboard?

When you say "not working any more"* what exactly do you mean? Yes, I know it's transparently obvious to you because you've been fighting with it for days, but it's new to us. What did it use to do that it doesn't do now?

As written, the RewriteRule would take any incoming request for any file or folder that doesn't exist, and route it to /folder/index.php. Are you absolutely positive that's what you want? In particular, are you certain you want a rewrite rather than a redirect? With a rewrite as coded, every single user will think they've entered the correct address, because they've all ended up in the Forums. With a redirect, they will see the correct address in their browser.

See thread in the immediate vicinity of this one for complete boilerplate on what happens to query strings. (Short version: Nothing, so you don't have to think about them.)


* You know you're getting old when you cringe at "anymore" written as one word.

g1smd

7:31 pm on Aug 18, 2011 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



OK, so you have moved the physical PHP files into a folder, but do you want to carry on using the old URLs or do you now want the URLs to include that folder name? Both things are possible.

Server filepaths (used inside the server) and URLs (used out there on the web) are not at all the same thing.

jancek

12:02 pm on Aug 21, 2011 (gmt 0)

10+ Year Member



@g1smd - I would like to carry on using old URLs.

@lucy24
Off cource, sorry.
Basic URLs with parameters (?p=123) are working, nice URLs are not working.

"The rewriting is not working anymore". The URLs which have been working before are not working now. Wordpress is showing 404 page. The htaccess file which I pasted to the first post is the standard Wordpress file. I am not sure how the URL rewriting is working in Wordpress. I guess the the index.php is processing all the requests and showing the requested content.

The problem is that htaccess file is somehow not working when it is placed in subfolder of WAMP server.

lucy24

7:24 pm on Aug 21, 2011 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



Is there a php script or similar that grabs everything with a query string ("parameters")? If those files are working, then clearly they are still getting to the right place. Do you have any filenames that occur both with and without queries?

The problem is that htaccess file is somehow not working when it is placed in subfolder of WAMP server.

!
You seem to be saying that you've moved the physical files and the htaccess, but the url that the user sees is still the same. How do users get to the folder that your htaccess is in?

Ordinarily the htaccess should live at the highest level that you're able to reach. In rare cases it can be appropriate to have a folder-specific htaccess (beyond the basic Options +Indexes, which doesn't really count) but in general you should be intercepting everything as soon as it arrives.

jancek

8:27 am on Aug 23, 2011 (gmt 0)

10+ Year Member



@lucy24 The domain.com is somehow through DNS directed to localhost/folder. I cant place htaccess to root folder, because I need to host 2 websites, each in one folder. I guess that the htaccess file is not working properly because it is not placed in root folder.

Sorry, if I am not writing the technical terms right, I am not native English, as you surely see :)

lucy24

8:52 am on Aug 23, 2011 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



htaccess files can go anywhere. But they only affect files and directories that are below them. And that means below them in the actual file structure, which may or may not be the same as what the user sees.

Simple example: One directory in my personal domain was formerly aliased to my son's userspace. (g1 will probably say that I have this backward and I should say that part of my son's userspace was aliased to my domain.) So my htaccess, at the top level of example.com, covered everything in the range:

home/{me}/{example.com}/{paintings,hovercraft,etexts etc}

but if I wanted to keep someone out of example.com/games, I had to maintain an entirely separate htaccess at

home/{son}/{example.com}/games

Which is why I recently undid the aliasing, after assuring son that this would have no effect whatsoever on his own domain-- which is at

home/{son}/{hisdomain.com}

If you can get it to work, some parts of your htaccess probably should go in the root folder where both domains can benefit from it. For example, you're probably blocking the same evil robots from both sites. If you put all your lockouts on this level, you won't have to say everything twice. But this can only be done if users really are passing invisibly through the root folder before landing where they want to be.

Hm. I know where I can experiment with this. The site isn't live yet, so it doesn't matter if I get 500 errors all day.

jancek

9:05 am on Aug 23, 2011 (gmt 0)

10+ Year Member



OK. Both websites (placed in subfolders of root) have the htaccess (also placed) like this (standard Wordpress):
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>

I would like to use only 1 htaccess placed in root for both websites. Does it exist the way to divide conditions and rules depending on the domain?

lucy24

9:11 pm on Aug 23, 2011 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



Yes, but it may be more trouble than it's worth. Unless the htaccess flatly refuses to work when placed in any other location. You'd have to remember to put a Condition involving HOST in every single rule. Unfortunately htaccess doesn't have parentheses and uber-conditions that would let you say "Don't even look at the next seventeen rules unless you meet such-and-such condition".

jancek

5:29 am on Aug 24, 2011 (gmt 0)

10+ Year Member



I solved that problem another way. I created 2nd virtual host on my server (localhost, localhost2) so now I have "2 root folders" where htaccess works without problem. Each host has separate port so I am able to reach each host from "outside". Thank you (lucy24) for trying to help me.