question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

rewriteRules does not appear to work (2.7.13)

See original GitHub issue

Running on Windows 8.1 64-bit in git-bash.

$ node --version
v0.12.4
'use strict';

var gulp = require('gulp');
var browserSync = require('browser-sync');
var reload = browserSync.reload;


gulp.task('watch', ['serve'], function () {
    gulp.watch('./**/*.*', reload);
});

gulp.task('serve', function () {
    browserSync.init(null, {
        server: {
            baseDir: './',
            directory: true
        },
        port:5000,
        ghostMode: {
            clicks: false,
            location: false,
            forms: false,
            scroll: false
        },
        rewriteRules: [
            {
                match: /WebsiteUrl/g,
                fn: function (match) {
                    return 'TEST';
                }
            }
        ],
        injectChanges: false,
        notify: false,
        reloadDelay: 0//1000
    }, function (err, bs) {
        require('opn')(bs.options.getIn(["urls", "external"]));
        console.log('Started connect web server on ' + bs.options.getIn(["urls", "external"]));
    });
});

gulp.task('default', [], function () {
    gulp.start('serve');
});
{
  "name": "emailtemplates",
  "version": "1.0.0",
  "description": "Email Templates for the Website project",
  "author": "",
  "devDependencies": {
    "browser-sync": "^2.7.13",
    "opn": "^3.0.2"
  }
}

Any ideas? Really frustrating. It seemed to work a few times, but not globally.

Issue Analytics

  • State:closed
  • Created 8 years ago
  • Comments:11 (3 by maintainers)

github_iconTop GitHub Comments

2reactions
repletecommented, Jul 13, 2015

@shakyShane That is great - I just wish that was in the documentation 😉

However, the issue was it only worked sometimes.

Anyway, I’m sure this bug will crop up somewhere else.

Thanks.

0reactions
digeomelcommented, Feb 15, 2017

Finally got it to work by reading this article: https://vinaygopinath.me/blog/tech/url-redirection-with-browsersync/ I had to specify middleware directly as a function, as described in the article above. When middleware is defined as described in the documentation, as an array of objects, it doesn’t work (i.e. trying to redirect by setting req.url doesn’t work).

Read more comments on GitHub >

github_iconTop Results From Across the Web

RewriteRule doesn't seem to work, but RedirectMatch does
I'm trying to use a RewriteRule to redirect requests for URLs to an updated URL string. This is for a WordPress site. /category-about...
Read more >
Error 403.14 when first attempting to access Symfony app in ...
When attempting to access it directly as below, it did work. So it seems that the .htaccess files are not being taken into...
Read more >
htaccess 301 Redirect does not work - ProcessWire
I used the Redirects Module. The URLs look as follow (all similar). old url: www.mysite.de/page.html or www.mysite.de/ ...
Read more >
What is meant by RewriteCond and RewriteRule in htaccess?
The RewriteRule pattern (a regex) matches the URL-path from the requested URL, which notably excludes the query string (you must use a RewriteCond...
Read more >
RewriteRule Flags - Apache HTTP Server Version 2.4
Use of the [NC] flag causes the RewriteRule to be matched in a case-insensitive manner. That is, it doesn't care whether letters appear...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found