简体   繁体   中英

.htaccess rewrites not working after migration from Windows server

Ok, so I have been developing a site for my employer in a subfolder of one of their other live sites. The URL structure in development was http://our-live-site.net/our-dev-site.com/index.php . The development server is running on Windows and the new server I've just migrated it to is a *nix Apache server. I'm not quite sure whether this is an issue with not having the extra directory in front or if it is a Windows/Linux difference in how they parse the .htaccess file. I'm inclined to believe the former rather than the latter after doing a bit of research on the matter. I have only 3 rules in my .htaccess file and I've isolated the problem to the last two, the rewrites.

    <IfModule mod_rewrite.c>
      RewriteEngine On
      RewriteRule ^(inc/ajax|inc/pages|js|fonts|moving-tips)($|/) - [L]

->    RewriteRule ^(.*).php template.php?page=$1 [NC]
->    RewriteRule ^(.*).php template.php?location=$1 [NC][QSA]
    </IfModule>

What I need to do is pass all requests to say http://new-site.com/some-page.php to http://new-site.com/template.php?page=some-page . I also need to keep the option of capturing another $_GET var for our location pages (they use a different template), hence the RewriteRule ^(.*).php template.php?location=$1 [NC][QSA] after the first rewrite. I have a feeling that I am overlooking something really simple with this, mainly because of the... well simplicity of the rules. Any help would be appreciated, I'm sure this is just an issue of having fresh eyes look at this.

Try:

RewriteCond %{REQUEST_URI}   !^/template.php
RewriteRule ^(.*).php template.php?page=$1&location=$1    [NC,L]

to replace both of those RewriteRules

What's happening is that when apache rewrites, it redirects internally and the rewritten path is passed BACK through all the rules, only stopping when the rewritten path (not query string) is the same as the unrewritten path.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM